title: How to notify an item has selected from data grid in wpf and using mvvm?
body: <p>I am trying to notify that an item is selected from data grid because I am opening a modal window while selecting a item from data grid. I am editing selected item in modal window and due to which I do not want to RaisedPropertychanged mechanism for selected item because when I try to modify the selected item, it opens another modal window. I am now trying to use event trigger to fix this issue but getting errors. Below is related code:</p>
  
  <p><strong>ViewModel:</strong></p>
  
  <pre><code>  public ObservableCollection&lt;Student&gt; sItems {
    get {
      return ssitems;
    }
   set {
     ssitems = value;
     RaisePropertyChanged( "sItems" );
    }
  } 
  private StudentsInformation studentInformation;
     public StudentsInformation studentInformationObject {
       get {
         return studentInformation;
       }
       set {
         studentInformation = value;
         RaisePropertyChanged( "studentInformationObject" );
       }
     }
  
  
  
  public RelayCommand&lt;Student&gt; SelectionChangedCommand {
        get;
        set;
      }
  </code></pre>
  
  <p>These lines of code are in constructor:</p>
  
  <pre><code>SelectionChangedCommand = new RelayCommand&lt;Student&gt;(
            item =&gt; {
              if( item != null ) {
                MessengerInstance.Send&lt;Student&gt;( item, "SelectedStudent" );
              }
            } );
  </code></pre>
  
  <p>This is collection which is bonded with datagarid.</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code> &lt;DataGrid x:Name="dataGrid" Grid.Row="1" Margin="5"
                                IsReadOnly="False"  ColumnHeaderHeight="30"
                                ItemsSource="{Binding Path=sItems}" AutoGenerateColumns="False" 
                                SelectedItem="{Binding Path=SelectedStudentObject, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"&gt;
                          &lt;DataGrid.Columns&gt;
                              &lt;!--&lt;DataGridCheckBoxColumn Header="Select" Binding="{Binding Path=myselect, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" /&gt;--&gt;
                              &lt;DataGridTextColumn Header="Name" Binding="{Binding name}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn Header="Enrollment" Binding="{Binding enrollment}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn Header="Score" Binding="{Binding score}"&gt;&lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn Header="Comment" Binding="{Binding comment}"&gt;&lt;/DataGridTextColumn&gt;
                          &lt;/DataGrid.Columns&gt;
                          &lt;i:EventTrigger EventName="SelectionChanged"&gt;
                              &lt;cmd:EventToCommand Command="{Binding SelectionChangedCommand}"
                                                  CommandParameter="{Binding SelectedItem}" /&gt;
                          &lt;/i:EventTrigger&gt;
                      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>If I remove the trigger section then datagrid populated with desired data. If Include the trigger code then I get this error message:</p>
  
  <p><em>Items collection must be empty before using ItemsSource.</em></p>
  
  <p>I would like to know is there other ways to fix this kind of things. I am using MVVM Light toolkit.</p>