I implemented a selection template similar to the one described in this post , using ViewModel to save the IsSelected value and bind ListViewItem.IsSelected to ViewModel IsSelected:
<ListView.ItemContainerStyle> <Style TargetType="{x:Type ListViewItem}"> <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/> </Style> </ListView.ItemContainerStyle>
This works overall, but I ran into a serious problem. Using a VirtualizingStackPanel as a panel in a list view, only visible ListViewItem are created. If I use "Ctrl + A" to select all elements or using the "Shift + Ctrl + End" key combination in the first element, all elements are selected, but for invisible elements ViewModel does not get its IsSelected set to true. This is logical because if the ListViewItem not created, the binding cannot work.
Has anyone experienced the same problem and found a solution (other than using VirtualizingStackPanel )?
listview wpf mvvm stackpanel virtualizingstackpanel
decasteljau Aug 13 '09 at 18:07 2009-08-13 18:07
source share