Add context menu in datagrid, how to get the select Item value

Expanding on Bolu’s comment you could use SelectedItem to get the current item. Below is a quick example:

<DataGrid ItemsSource="{Binding Source}" SelectedItem="{Binding SelectedItemProperty, Mode=TwoWay}">
            <MenuItem Command="{Binding MyCommand}" Header="MyCommand"/>
        <DataGridTextColumn Header="Name" Binding="{Binding Key, Mode=TwoWay}" Width="1*"/>
        <DataGridTextColumn Header="Value" Binding="{Binding Value, Mode=TwoWay}" Width="3*"/>

SelectedItem is now bound to SelectedItemProperty in the ViewModel.

Leave a Comment