This behaviour of the Selector is to be expected, because it can operate only with loaded UI elements. Due enabling virtualization you have loaded only those elements which contains in visible area. So, Selector does not "know" about others.
For fix this you must do so, that Selector "know" about previously selected items. In other word, you must to prohibit unloading any UI element which was selected.
First, create own virtualizing panel with blackjack and hookers:
public class MyVirtualizingStackPanel : VirtualizingStackPanel
{
protected override void OnCleanUpVirtualizedItem(CleanUpVirtualizedItemEventArgs e)
{
var item = e.UIElement as ListBoxItem;
if (item != null && item.IsSelected)
{
e.Cancel = true;
e.Handled = true;
return;
}
var item2 = e.UIElement as TreeViewItem;
if (item2 != null && item2.IsSelected)
{
e.Cancel = true;
e.Handled = true;
return;
}
base.OnCleanUpVirtualizedItem(e);
}
}
Next, replace default panel in the ListBox, ListView, TreeView or other user controls which provide selector.
For example, via style:
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<blackjackandhookers:MyVirtualizingStackPanel/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
... or, directly in your selector:
<YourSelector.ItemsPanel>
<ItemsPanelTemplate>
<blackjackandhookers:MyVirtualizingStackPanel/>
</ItemsPanelTemplate>
</YourSelector.ItemsPanel>
Enjoy!
I hope my answer will help you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…