我想我需要做的視覺樹行?
是的,你可以使用的RelativeSource綁定到你的CellTemplate父DataGridRow的任何屬性:
<TextBlock Text="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
所以這樣的事情應該工作:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ComboBox x:Name="cmb">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
</ComboBox>
<TextBlock x:Name="txt" Text="..." Visibility="Collapsed" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="True">
<Setter TargetName="cmb" Property="Visibility" Value="Collapsed" />
<Setter TargetName="txt" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
來源
2016-12-14 11:35:32
mm8