title: Wpf MVVM Selecting/unSelecting Item in DataGrid
body: <p>I'm working on an MVVM project and I have this Code in one of the the views: </p>
  
  <pre><code>&lt;GroupBox   Header="Defaut"  BorderBrush="#FF4EA8DE" FontSize="16" Foreground="#FF436EFF"  &gt;
                      &lt;DataGrid Background="Transparent" FontSize="14" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" AutoGenerateColumns="False" Style="{x:Null}" 
                                ItemsSource="{Binding ErrorList}"&gt;
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn Width="0.5*" Header="{DynamicResource Numéro Cordon}" Binding="{Binding BeadName}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn Width="0.5*" Header="{DynamicResource Indice Image}" Binding="{Binding IndiceImage}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn Width="0.5*" Header="{DynamicResource Défaut}" Binding="{Binding DispDefault}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTemplateColumn Header="{DynamicResource Criticité}" Width="0.5*"&gt;
                                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;Label Content="{Binding IsError, Converter={StaticResource IsErrorToCriticityLevel}, Mode=OneWay}"&gt;&lt;/Label&gt;
                                      &lt;/DataTemplate&gt;
                                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
                              &lt;/DataGridTemplateColumn&gt;
  
                          &lt;/DataGrid.Columns&gt;
  
                          &lt;DataGrid.CellStyle&gt;
                              &lt;Style TargetType="DataGridCell"&gt;
                                  &lt;Setter Property="CmdB:CommandBehavior.Event" Value="MouseDown" /&gt;
                                  &lt;Setter Property="CmdB:CommandBehavior.Command" Value="{Binding DataContext.RobotErrorSelectionChangedCommand, 
                                                                                                  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type controls:MetroWindow}}}"/&gt;
                                  &lt;Setter Property="CmdB:CommandBehavior.CommandParameter" Value="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/&gt;
                                  &lt;Style.Triggers&gt;
                                      &lt;Trigger Property="IsSelected" Value="true"&gt;
                                          &lt;Setter Property="BorderBrush" Value="#FF6593CF" /&gt;
                                          &lt;Setter Property="Background" Value="#FF6593CF" /&gt;
                                      &lt;/Trigger&gt;
                                  &lt;/Style.Triggers&gt;
                              &lt;/Style&gt;
                          &lt;/DataGrid.CellStyle&gt;
  
                          &lt;i:Interaction.Triggers&gt;
                              &lt;i:EventTrigger EventName="SelectionChanged"&gt;
                                  &lt;i:InvokeCommandAction Command="{Binding RobotErrorSelectionChangedCommand}" CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" /&gt;
                              &lt;/i:EventTrigger&gt;
                          &lt;/i:Interaction.Triggers&gt;
                      &lt;/DataGrid&gt;
                  &lt;/GroupBox&gt;
  </code></pre>
  
  <p>What I want to do is to be able to unselect the selected item in this list, however I can't find how to access it.  </p>
  
  <p>Here is the code in the ViewModel related to this list:</p>
  
  <pre><code>ObservableCollection&lt;Erreur&gt; _ErrorList;
      public ObservableCollection&lt;Erreur&gt; ErrorList
      {
          get { return _ErrorList; }
          set { _ErrorList = value; RaisePropertyChanged("ErrorList");}
      }
  
  
  private RelayCommand&lt;Erreur&gt; _RobotErrorSelectionChangedCommand;
      public RelayCommand&lt;Erreur&gt; RobotErrorSelectionChangedCommand
      {
          get
          {
              return _RobotErrorSelectionChangedCommand
                  ?? (_RobotErrorSelectionChangedCommand = new RelayCommand&lt;Erreur&gt;(
                  (Erreur err) =&gt;
                  {
                      if (err != null)
                      {
                          viewservice.OpenDialog(new ErreurImageViewModel(err), ServiceLocator.Current.GetInstance&lt;MainViewModel&gt;());
  
                      }     
                  }));
          }
      }
  </code></pre>
  
  <p>Thank you for any help or advice. </p>