I'm learning wpf with mvvm light and i'm face an issue. I've a usercontrol with a datagrid that's loaded with a query.
Now i'd like to add an event on the selectedIndex to retrieve the selected line and after that i'll pass the value to an other user control.
the issue is that my event is never fired.
Here is what i did
<DataGrid HorizontalAlignment="Left" Name="dgUser" VerticalAlignment="Top" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" SelectedItem="{Binding selectedRow, Mode=TwoWay}" Width="800" Height="253" >
Here is the code of my viewmodel
public RelayCommand selectedRow { get; private set; }
private int _selectedIndex;
public int SelectedIndex
{
get { return _selectedIndex; }
set
{
_selectedIndex = value;
RaisePropertyChanged("SelectedIndex");
}
}
/// <summary>
/// Initializes a new instance of the ListUserViewModel class.
/// </summary>
public ListUserViewModel()
{
selectedRow = new RelayCommand(() => SelectedRowChange());
SelectedIndex = 2;
}
private void SelectedRowChange()
{
System.Windows.MessageBox.Show("test");
}
My row is not selected with SelectedXIndex = 2 and nothing happen when i select an other row