Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Windows ListView doesn't visualise items when they have binded command with a parameter #22731

Open
AlexShovkoplyas opened this issue May 30, 2024 · 4 comments
Labels
area-controls-listview ListView and TableView platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@AlexShovkoplyas
Copy link

Description

I hope a sample solution is selfdescriptive.
Screenshots:
from windows app
image

from Android app
image

Windows app in debug shows binding failures:
'Name' property not found on 'ListViewMVVMFun.MainPageViewModel', but if I remove binding to command - that binding failures dissapear

Steps to Reproduce

Xaml causing the issue :

in MainPage.xaml.cs

<ListView ItemsSource="{Binding Path=People}">
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="viewmodels:Person">
            <TextCell Text="{Binding Name}"
                      Command="{Binding DoCommand, Source={RelativeSource AncestorType={x:Type viewmodels:MainPageViewModel}}}"
                      CommandParameter="{Binding .}"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

in MainPage.xaml.cs

BindingContext = new MainPageViewModel();
InitializeComponent();

in MainPageViewModel.cs

internal partial class MainPageViewModel : ObservableObject
{
    [ObservableProperty]
    private bool _result = false;

    [ObservableProperty]
    private List<Person> _people;

    public MainPageViewModel()
    ...

    [RelayCommand]
    private void Do(Person person)
    ...
}
class Person
{
    public Person(int id, string name, int age)
    ...

    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

Link to public reproduction project repository

https://github.com/AlexShovkoplyas/ListViewMVVMFun

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11 (.net8.0-windows10.0.19041.0)

Did you find any workaround?

No

Relevant log output

No response

@AlexShovkoplyas AlexShovkoplyas added the t/bug Something isn't working label May 30, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 30, 2024
@RoiChen001
Copy link

Can repro this issue at Windows platform on the latest 17.11.0 Preview 1.0(8.0.21/8.0.40).

@AlexShovkoplyas
Copy link
Author

Workaround from closed issue works - #20883 (comment)

@bengavin
Copy link

We've gotten around this by using the Community Toolkit's EventToCommandBehavior. Kinda of a hacky workaround, but it seems to work anyway :)

<toolkit:EventToCommandBehavior 
           EventName="Clicked" 
           Command="{Binding BindingContext.ShowOptionsCommand, Source={x:Reference view}}" 
           CommandParameter="{Binding}" />

@PureWeen PureWeen added the area-controls-listview ListView and TableView label May 31, 2024
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 4, 2024
@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-listview ListView and TableView platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants