Reputation: 1469
I have a RadGridView
which has a context menu and in this context menu I have a button which I set a command on in the parameters I want to pass the gridview itself - how do I do this?
<telerik:RadGridView Height="620" HorizontalAlignment="Right" Name="radGridView2" VerticalAlignment="Top" Width="1564" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" ItemsSource="{Binding Collections}" BorderBrush="#FFD7D2D2" FontFamily="Mangal" FontSize="14" Loaded="radGridView2_Loaded" AutoGenerateColumns="False"
RowStyleSelector="{StaticResource rowStyleSelector}" GroupRenderMode="Flat" ShowColumnSortIndexes="True" CanUserFreezeColumns="False" CanUserResizeColumns="False"
DataContext="{Binding}" IsReadOnly="True" DataLoading="radGridView2_DataLoading" DataLoaded="radGridView2_DataLoaded" GroupPanelForeground="#FFF01D1D"
ShowColumnFooters="True" ShowGroupFooters="True" AutoExpandGroups="True" GridLinesVisibility="Both" Grid.Row="1" Margin="0,0,35,0" MouseDoubleClick="radGridView2_MouseDoubleClick"
ColumnWidth="52*">
<telerik:RadGridView.ContextMenu>
<ContextMenu>
<ContextMenu.Items>
<Button Command="{Binding PrintCommand}" CommandParameter="{Binding}">
<Button.Content>
<TextBlock Text="Print"/>
</Button.Content>
</Button>
</ContextMenu.Items>
</ContextMenu>
</telerik:RadGridView.ContextMenu>
</telerik:RadGridView>
Using {Binding}
as my CommandParameter
does not work it gives me the row in which I click - the data context of that row - which is some business object - how do I get the containing grid.
Upvotes: 1
Views: 457
Reputation: 17063
If you mean with 'containing grid' the RadGridView
try
CommandParameter="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
You will need the PlacementTarget
property because ContextMenu
has its own VisualTree.
Upvotes: 1
Reputation: 2066
Use RelativeSource to bind to the parent element data context:
CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"
Upvotes: 0