I have a ListView on my WPF window, and I have a button that is suppose to select all. First how do you get the button to do select all the items in the listview.
Secondly, I need my ViewModel to then go through all the selected items. How do I obtain this information in my ViewModel?
I’ve read you can do this with IsSelected property but has a bug, where the local property overrides the binding property so if it has already been selected before then it doesn’t appear to be selected again – or something like that. It seems convoluted. The blog that looks into this problem
Then I’ve read this blog Data binding to selected items which also seems very convoluted.
I would like to know if it has to be that convoluted and that those examples are the only way forward.
XAML:
<ListView Name="sources_ListView" Grid.RowSpan="1" ItemsSource="{Binding Path=Sources}">
<ListView.View>
<GridView>
<GridViewColumn Width="290" Header="Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=OriginalPath}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="80" Header="Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Type}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Button Grid.Row="0" Grid.Column="0" Content="Select All" Name="selectAllSources_Button" Margin="3" />
<Button Grid.Row="0" Grid.Column="1" Content="Deselect All" Name="deselectAllSources_Button" Margin="3" />
<Button Grid.Row="0" Grid.Column="3" Content="Remove Selected" Name="removeSelected_Button" Margin="3" Width="100" HorizontalAlignment="Right" />
@RV1987 Thanks for your answer, that was definately a big part of it. However for the rest of it I found this blog which detailed exactly how to do it with source code. Definitely a worth while read.
Bad Entropy Blog
Thanks