Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
XamDataGrid column header with context menu and command parameter
posted

I have a control template defined to create a customized column header.  In the template I have a context menu and am trying to pass back the target column as a command parameter.  I have the actual command binding working and the following passes back the xamDataGrid, but I would like to pass back the index or ideally the bound Field object for that column.  When the command fires, I need to know which column the user right clicked on.  Open to other/better ways of doing it as well!

<ControlTemplate x:Key="Header1">
<Grid VerticalAlignment="Bottom">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="2"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"
Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}">
<Label.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Rename" Command="{Binding DataContext.RenameCommand}"
   CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
</ContextMenu>
</Label.ContextMenu>
</Label>
<Border BorderThickness="1" Grid.Row="1" BorderBrush="LightGray"/>
<Border BorderThickness="1" Grid.Row="2" Height="38"/>
</Grid>
</ControlTemplate>

Parents Reply Children
No Data