0
私はその中にテキストボックスを持つDataGridTemplateColumnを持っています。行にカーソルを置くと、他のすべてのフォアグラウンドがテキストボックスを除いて白くなります。マウスを行の上に置いたときに、他のテキストブロック/フォントと一致するようにフォアグラウンドの変更を行うために、どのようなスタイルをテキストボックスに適用できますか?あなたはTextBox
のための追加Style
を定義する必要がDataGridTemplateColumn行のホバーのテキストボックスの前景
例XAML
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<TextBox Text="Test 123" />
<TextBlock Text="Test 123" />
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
スタイリング
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="BorderBrush"
Value="{x:Null}" />
<Setter Property="Foreground"
Value="{StaticResource BlackBrush}" />
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="BorderBrush"
Value="{x:Null}" />
<Setter Property="Foreground"
Value="{StaticResource BlackBrush}" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{StaticResource RedBrush}" />
<Setter Property="Foreground"
Value="{StaticResource WhiteBrush}" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Padding"
Value="5, 10" />
<Setter Property="IsTabStop"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="{Binding Path=Background, RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
<Setter Property="Foreground"
Value="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
<Setter Property="BorderBrush"
Value="{Binding Path=BorderBrush, RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
</Trigger>
</Style.Triggers>
</Style>