Skip to content

XAML Visual Tree does not represent the underlaying data #10240

Open
@AuderixDev

Description

Describe the bug

Working with Listview and ListView.ItemTemplate I noticed a strange behaviour.
I debugged it with the Visual Tree Viewer and noticed, that after removing items from the Listview, some items are reappearing in the XAML Visual Tree.
Further interactions with the ListView leads to wrong beahviour, like Loaded-Events are not triggered, because the Item already exists.

Steps to reproduce the bug

MainPage.xaml

...
 <ListView ItemsSource="{Binding NameList}" x:Name="outerList">
   <ListView.ItemTemplate>
     <DataTemplate>
       <StackPanel Orientation="Horizontal" x:Name="innerobject">
         <TextBlock Text="{Binding Id}" />
         <Button Content="Remove"
                 Command="{Binding DataContext.RemoveMe, ElementName=outerList}"
                 CommandParameter="{Binding Id}"/>

       </StackPanel>
       
     </DataTemplate>
    </ListView.ItemTemplate>
 </ListView>
...

MainModel.cs

...
  public IListState<Customer> NameList => ListState<Customer>.Empty(this);

  public async Task AddToList()
  {
      await NameList.AddAsync(new Customer());
  }

  public async Task RemoveMe(Guid id)
  {
      await NameList.RemoveAllAsync(match: x => x.Id == id);
  }

  public partial record Customer()
  {
      public Guid Id { get; } = Guid.NewGuid();
  }
...

Expected behavior

The Visual Tree should represent the underlaying data.

Screenshots

uno

NuGet package version

None

Windows version

No response

Additional context

Comes from here: unoplatform/uno#19068
It's not an Uno-Platform-Problem.

Metadata

Assignees

No one assigned

    Labels

    area-ListsListView, GridView, ListBox, etcbugSomething isn't workingneeds-reproneeds-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions