DataGrid loses selection

Viewed 1046

There is a collection of categories with products.

Each category is represented in the interface by the AvalonDock tab, which has a DataGrid with products.

Now when switching from tab to tab, DataGrid updates the collection every time. If you select a pair of rows in the table on the first tab, switch to the second tab and return to the first one, the selection disappears.

What could be the problem?

XAML:

<xcad:DockingManager DocumentsSource="{Binding Examples}">
    <xcad:DockingManager.LayoutItemTemplate>
        <DataTemplate>
            <ListBox ItemsSource="{Binding Content.Items}" 
                     SelectionMode="Extended" />
        </DataTemplate>
    </xcad:DockingManager.LayoutItemTemplate>
    <xcad:LayoutRoot />
</xcad:DockingManager>>

Code-behind:

public partial class MainWindow : Window
{
    public class Example
    {
        public List<int> Items { get; } = new List<int>();

        public Example()
        {
            for (var i = 0; i < 10; i++)
            {
                Items.Add(i);
            }
        }
    }

    public List<Example> Examples { get; } = new List<Example>();

    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        Examples.Add(new Example());
        Examples.Add(new Example());
    }
}

enter image description here

1 Answers
Related