DataGridの行を選択した際に、選択行の背景色を青、文字色を白にしていますが、
セルに配置しているradiobuttonの文字色も選択時に、白色に変更したいのですが
なかなか良い方法がみつかりません。どなたか良い方法をご存じの方がいらっしゃいましたら
教えて頂けないでしょうか?よろしくお願い致します。
1 件の回答
RelativeSource
を使用してRadioButton
の上位にあるDataGridCell
やDataGridRow
を参照すれば実現可能です。
例えばDataGridCell.Foreground
には既定の文字色が反映されますので、これをRadioButton.Foreground
にバインドすることが出来ます。
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton
Content="radio"
Foreground="{Binding RelativeSource={RelativeSource AncestorType=DataGridCell}, Path=Foreground}">
</RadioButton>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
またIsSelected
プロパティにDataTrigger
を設定する方法でも実現できます。
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton
Content="radio">
<RadioButton.Style>
<Style
TargetType="RadioButton">
<Style.Triggers>
<DataTrigger
Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected}"
Value="True">
<Setter
Property="Foreground"
Value="#fff" />
</DataTrigger>
</Style.Triggers>
</Style>
</RadioButton.Style>
</RadioButton>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>