I have a WPF DataGrid, the ItemsSource
property is bound to the viewmodel.
On click on a Button a method is doing work on the selected rows of the DataGrid.
When the work is done, I would like to unselectAll the DataGrid's rows from the viewmodel, how can I achieve this in a MVVM way?
XAML :
<DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding ObCol_View}"
SelectedItem="{Binding SelectedItem}
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<GalaCmd:EventToCommand Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding SelectedItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
<Button Content="Apply" Command="{Binding PerformCommand}"/>
The viewmodel
public class ViewModelprices_manager<T> : WindowViewModel
{
public ViewModelprices_manager()
{
SelectionChangedCommand = new RelayCommand<IList>
(items =>
{
SelectedItems = items;
}
);
myObCol_View = new ObservableCollection<View_prices_manager<T>>();
}
public IList SelectedItems { get; set; }
private readonly ObservableCollection<View_prices_manager<T>> myObCol_View;
public ObservableCollection<View_prices_manager<T>> ObCol_View_Parametric { get { return myObCol_View; } }
public RelayCommand<IList> SelectionChangedCommand
{
get;
private set;
}
private RelayCommand myPerformCommand;
public RelayCommand PerformCommand
{
get
{
if (myPerformCommand == null)
myPerformCommand = new RelayCommand(PerformCommandAction);
return myPerformCommand;
}
}
private void PerformCommandAction()
{
perform();
}
public void perform()
{
foreach (View_prices_manager<T> item in SelectedItems)
{
item.Price *= ratio;
}
//DataGrid.UnselectAll <-- Here I want to unselect all to reset the selection in SelectedItems
}
}