This selector behavior is to be expected since it can only work with loaded user interface elements. Thanks to the possibility of virtualization, you have loaded only those elements that are contained in the visible area. Thus, the selector does not βknowβ about others.
To fix this, you must do this so that the Selector βknowsβ about previously selected items. In other words, you must prevent the unloading of any user interface element that has been selected.
First, create your own virtualization panel with blackjack and prostitutes:
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); } }
Then replace the default panel in ListBox, ListView, TreeView, or other custom controls that provide a selector. For example, through the 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 it!
Hope my answer helps you.
nvkokorin Apr 09 '15 at 18:04 2015-04-09 18:04
source share