Skip to content

ArgumentNullException when removing items from ObservableCollection bound to ItemsControl with CardExpander items #1140

@bujma

Description

@bujma

Describe the bug

System.ArgumentNullException: 'Value cannot be null. Parameter name: defaultDestinationValue' when removing items of ObserableCollection<Model> bound from ViewModel class to ItemsControl in Window with ItemTemplate templated with CardExpander after expanding any CardExpander.

To Reproduce

Situation:

  • MainWindow (pure Windowdescendant, no FluentWindow) with Resources <ui:ThemesDictionary Theme="Light" /> and <ui:ControlsDictionary />.
  • MainWindow with simple ViewModel class as DataContext.
  • ViewModel class with ObservableCollection<Model> Items property bound to ItemsControl having ItemTemplate as CardExpander.

Steps:

  1. In runtime, fill the Items with some Model items (button [Reload Items] calling Items = new ObservableCollection<Model>(list)).
  2. Expand any CardExpander.
  3. Remove any item/all items/assign new instance of ObservableCollection to Items property (buttons [Delete], [Remove All Items] or [Reload Items] calling Items.Remove(item), Items.Clear() or code from step 1).
    => exception will be thrown

Description:

  • If you use default WPF style (no WPF-UI resources in MainWindow.xaml), everything will work.
  • If you use WPF-UI resources in MainWindow.xaml, exception is thrown.
  • If you do not expand a card (skip step 2), all will work with or without WPF-UI resources.

ErrorProof.zip

Expected behavior

No exception thrown. Removing items from ObservableCollection or assigning new instance should have no such impact.

Screenshots

No response

OS version

Windows 10 Pro 22H2 19045.4529

.NET version

4.7.2

WPF-UI NuGet version

3.0.4

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions