2012-05-06 58 views
2

我在GridColumn.CellTemplate中通過ElementName綁定了Hyperlink.Command。我想使用RelativeSource進行綁定,但我無法弄清楚如何做。任何在這方面的幫助將不勝感激。謝謝....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> 

回答

2

您必須指定AncestorType

Command="{Binding DataContext.ToggleCommand, 
        RelativeSource={RelativeSource AncestorType=dxg:GridControl}}" 
+0

完美!感謝你的幫助 –