I'm trying to figure out how to bind
a button
to select all the rows
(items) in a DataGrid
using MVVM
(Caliburn.Micro).
I'm looking to have this button be separate from the DataGrid
itself.
Something like:
View:
<Button x:Name="SelectAll"/>
<DataGrid x:Name="People">
<DataGrid.RowStyle>
<Style>
<Setter Property="DataGridRow.IsSelected"
Value="{Binding IsPersonSelected}" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="{Binding PersonName, UpdateSourceTrigger=PropertyChanged}" />
</DataGrid.Columns>
</DataGrid>
ViewModel:
public bool _isPersonSelected = false;
public bool IsPersonSelected
{
get { return _isPersonSelected; }
set
{
_isPersonSelected = value;
NotifyOfPropertyChange(() => IsPersonSelected);
}
}
public void SelectAll()
{
if(IsPersonSelected == true)
{
IsPersonSelected = false;
}
else
{
IsPersonSelected = true;
}
}
This doesn't work though, perhaps there is another way of selecting rows in a DataGrid
using some sort of binding for MVVM?
Or some way of calling the SelectAllCommand
RoutedUICommand
for DataGrid
s?
Suggestions/help would be greatly appreciated.