dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.02k stars 1.73k forks source link

ListView command hides cells' content #14234

Open BineeMan opened 1 year ago

BineeMan commented 1 year ago

Description

When using a command and command parameter inside of ViewCell.ContextActions' MenuItem in a ListView, all cells become not visible. You still can hover over cells and see that their area is highlighted but there is no content inside and context menu is not working. Without a CommandParameter or without a Command attribute everything works fine, the problem appears only when using both Command and CommandParameter attributes. Here is the part of code that hides ViewCells:

 <ListView x:Name="listView" ItemsSource="{Binding Monkeys}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="{x:Type x:String}">
                    <ViewCell>
                        <ViewCell.ContextActions>
                            <MenuItem Text="Favorite"
                                      Command="{Binding Source={x:Reference listView}, Path=BindingContext.RemoveCommand}" 
                                      CommandParameter="{Binding}" />  <!--Problem Is Here-->
                        </ViewCell.ContextActions>
                        <Label Text="{Binding .}" />
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

To return all ViewCells I have to remove " CommandParameter="{Binding}" attribute.

 <ListView x:Name="listView" ItemsSource="{Binding Monkeys}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="{x:Type x:String}">
                    <ViewCell>
                        <ViewCell.ContextActions>
                            <MenuItem Text="Favorite"
                                      Command="{Binding Source={x:Reference listView}, Path=BindingContext.RemoveCommand}"   />  
                        </ViewCell.ContextActions>
                        <Label Text="{Binding .}" />
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

This happens only on Windows, on Android it works fine.

Steps to Reproduce

  1. Create new .NET 7 MAUI App
  2. Install CommunityToolkit.MVVM
  3. Create ListView on MainPage with data template and context menu
  4. Create a model class for main page
  5. Set ItemSource to ObservableCollection from model.

Link to public reproduction project repository

https://github.com/BineeMan/MauiListViewBug/tree/main/MauiApp4

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

BineeMan commented 1 year ago

Any workawround for this issue? I really need a list which is compatible with MVVM and where a user can choose cells and interact with it. And I've tried CollectionView, it has the same issue.

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on Windows platform with sample project. https://github.com/BineeMan/MauiListViewBug/tree/main/MauiApp4 image

KonstantinKellermann commented 1 year ago

Have you tried using the CollectionView? We had a similar problem using the ListView. In our case the CollectionView fixed it.

You might have to arrenge the height of the CollectionView but it works for us.

jonathanMelly commented 7 months ago

Have you tried using the CollectionView? We had a similar problem using the ListView. In our case the CollectionView fixed it.

You might have to arrenge the height of the CollectionView but it works for us.

Thanks a lot, this workaround works for me too ;-)