DataGridTemplateColumn行悬停文本框前景(DataGridTemplateColumn row hover textbox foreground)
我有一个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>
I have a DataGridTemplateColumn with a textbox inside of it. When I hover on the row, all other Foregrounds turn white except the textbox. What kind of styling can I apply to the textbox to make it's foreground change to match the other textblocks/fonts when the mouse is hovering over the row?
Example XAML
<DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <TextBox Text="Test 123" /> <TextBlock Text="Test 123" /> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>Styling
<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>最满意答案
您需要为TextBox定义一个额外的Style :
<Style TargetType="TextBox"> <Style.Triggers> <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="True"> <Setter Property="Foreground" Value="White" /> </DataTrigger> </Style.Triggers> </Style>You need to define an additional Style for the TextBox:
<Style TargetType="TextBox"> <Style.Triggers> <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="True"> <Setter Property="Foreground" Value="White" /> </DataTrigger> </Style.Triggers> </Style>更多推荐
Property,<Setter,Value,电脑培训,计算机培训,IT培训"/> <meta name="des
发布评论