As @nobody suggested, switching between tabs seems to refresh the layout, and the selection state is lost. If the user interface cannot save the selection state, you can use the next level, such as a presentation or presentation model, to do the same.
In this case, adding the IsSelected property for the view-model element and binding to the ListViewItem should do the trick.

XAML:
<Grid> <xcad:DockingManager DocumentsSource="{Binding Examples}"> <xcad:DockingManager.DocumentHeaderTemplate> <DataTemplate> <TextBlock Text="Doc" /> </DataTemplate> </xcad:DockingManager.DocumentHeaderTemplate> <xcad:DockingManager.LayoutItemTemplate> <DataTemplate> <ListBox DisplayMemberPath="Value" ItemsSource="{Binding Content.Items}" SelectionMode="Extended"> <ListBox.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="LightBlue" /> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> </Style> </ListBox.Resources> </ListBox> </DataTemplate> </xcad:DockingManager.LayoutItemTemplate> <xcad:LayoutRoot /> </xcad:DockingManager> </Grid>
Code for:
public partial class MainWindow : Window { public class ExampleItem { public int Value { get; set; } public bool IsSelected { get; set; } } public class Example { public List<ExampleItem> Items { get; } = new List<ExampleItem>(); public Example() { for (var i = 0; i < 10; i++) { Items.Add(new ExampleItem { Value = i }); } } } public List<Example> Examples { get; } = new List<Example>(); public MainWindow() { InitializeComponent(); DataContext = this; Examples.Add(new Example()); Examples.Add(new Example()); } }
source share