How to set a binding in WPF Toolkit Datagrid's ContextMenu CommandParameter
Posted
by Boris Lipschitz
on Stack Overflow
See other posts from Stack Overflow
or by Boris Lipschitz
Published on 2010-05-16T23:04:24Z
Indexed on
2010/05/16
23:10 UTC
Read the original article
Hit count: 1022
I need to create a ContextMenu where I want to pass a currently selected index of the datagrid to a ViewModel using CommandParameter. The following Xaml code doesn't work. What might be the problem?
<dg:DataGrid ItemsSource="{Binding MarketsRows}"
<dg:DataGrid.ContextMenu >
<ContextMenu >
<MenuItem Header="Add Divider"
CommandParameter="{Binding Path=SelectedIndex,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGrid}}}"
Command="{Binding Path= AddDividerCommand}"/>
</ContextMenu>
</dg:DataGrid.ContextMenu>
</dg:DataGrid>
© Stack Overflow or respective owner