我在通过ElementName绑定的GridColumn.CellTemplate中有Hyperlink.Command。我想使用RelativeSource进行绑定,但我无法弄清楚如何这样做。在这方面的任何帮助将非常感激。感谢....
<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>
答案 0 :(得分:2)
您必须指定AncestorType:
Command="{Binding DataContext.ToggleCommand,
RelativeSource={RelativeSource AncestorType=dxg:GridControl}}"