2

I have Hyperlink.Command within a GridColumn.CellTemplate that I bind via an ElementName. I'd like to do the binding using RelativeSource but I couldn't figure out how to do so. Any help in this regard would br greatly appreciated. Thanks....

<dxg:GridControl
    DataContext="{StaticResource viewModel}"
    Name="grid"
    ItemsSource="{Binding Details}"
    Grid.Row="1">
    <dxg:GridControl.View>
        <dxg:TableView
            ShowGroupPanel="False" />
    </dxg:GridControl.View>
    <dxg:GridControl.Columns>
        <dxg:GridColumn
            Header="Even or Odd"
            Width="200"
            FieldName="EvenOrOdd">
            <dxg:GridColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock
                        Padding="4,0">
                    <Hyperlink
                            Command="{Binding DataContext.ToggleCommand, ElementName=grid}"
                            CommandParameter="{Binding RowData.Row}">
                        <TextBlock
                                Text="{Binding Value}" />
                    </Hyperlink>
                </TextBlock>
                </DataTemplate>
            </dxg:GridColumn.CellTemplate>
        </dxg:GridColumn>
        <dxg:GridColumn
            FieldName="Number"
            Width="200" />
    </dxg:GridControl.Columns>
</dxg:GridControl>
4

1 回答 1

2

You have to specify the AncestorType:

Command="{Binding DataContext.ToggleCommand,
                  RelativeSource={RelativeSource AncestorType=dxg:GridControl}}"
于 2012-05-06T18:20:08.293 回答