1

我有RadGridView一个上下文菜单,在这个上下文菜单中我有一个按钮,我在要传递gridview本身的参数中设置命令 - 我该怎么做?

<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>

使用{Binding}as myCommandParameter不起作用它给了我单击的行 - 该行的数据上下文 - 这是一些业务对象 - 我如何获取包含网格。

4

2 回答 2

1

如果您的意思是“包含网格”,请RadGridView尝试

CommandParameter="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}"

您将需要该PlacementTarget属性,因为ContextMenu它有自己的 VisualTree。

于 2013-10-02T17:45:40.027 回答
0

使用 RelativeSource 绑定到父元素数据上下文:

CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"
于 2013-10-02T17:42:37.303 回答