I am trying to retrieve row info from a datagrid after a double click event. I have the event setup, but now I just need to setup the function to retrieve the data from the row.
XAML:
<DataGrid
Width="Auto"
SelectionMode="Extended"
IsReadOnly="True"
Name="ListDataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding ListFieldObject.MoviesList}"
DataContext="{StaticResource MovieAppViewModel}"
cal:Message.Attach="[Event MouseDoubleClick] = [Action RowSelect()]">
<DataGrid.Columns>
<DataGridTextColumn Width="200" IsReadOnly="True" Header="Title" Binding="{Binding Title}"/>
<DataGridTextColumn Width="100" IsReadOnly="True" Header="Rating" Binding="{Binding Rating}"/>
<DataGridTextColumn Width="100" IsReadOnly="True" Header="Stars" Binding="{Binding Stars}"/>
<DataGridTextColumn Width="93" IsReadOnly="True" Header="Release Year" Binding="{Binding ReleaseYear}"/>
</DataGrid.Columns>
</DataGrid>
C# (MVVM ViewModel):
public void RowSelect()
{
//now how to access the selected row after the double click event?
}
Thanks Much!
You can just pass $dataContext on your XAML:
And change your method to:
//EDIT
Sorry, the above solution will work only if the action is on the datatemplate itself… another solution would be to have a SelectedItem bind and just use it on your method:
and on your code: