Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
XamDataGrid last added item is duplicated (just visual)
posted

Hello,

I have a XamDataGrid bound to an ListCollectionView (which has an underlying CollectionViewSource that is referencing an ObservableCollection).

When I add an item and update the ObservableCollection then the last added item is duplicated in the visual display.

Adding a second item will remove the duplicate but add a duplicated of the second item.

I have attached a sample project that shows the issue.

In "ItemListViewModel.cs" when I comment the row 44, then the issue disappears.

  1. Why is assigning a filter creating this issue?
  2. Is there a workaround to fix the issue?

Thanks in advice.

WpfApp1_gridDuplicates.zip

  • 7555
    Offline posted

    Hello,

    Thank you for sharing your sample for the investigation, so i debug the code and looks like a timing issue, your filter been applied too early that litemlist view is not yet updated, so when i put the filter in beginInvoke its working fine . 

    So your code would be :

    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
    {
    ItemListView.Filter = o => ItemListViewFilter((DataItem)o);
    }));