首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >彩色风格Textblock

彩色风格Textblock
EN

Stack Overflow用户
提问于 2015-10-20 14:35:27
回答 1查看 3.2K关注 0票数 3

我有这个默认前景颜色为白色的文本块

代码语言:javascript
复制
 <TextBlock Text="First Cmd" Grid.Row="0" TextAlignment="Center"  Margin="4" TextWrapping="Wrap" Foreground="White" Style="{DynamicResource ABC}">
       <TextBlock.InputBindings>
                <MouseBinding  Command="{Binding AAA}" MouseAction="LeftClick" />
       </TextBlock.InputBindings>
 </TextBlock>

当鼠标在文本块上时,基础颜色必须更改为黑色,但是这个样式的不能工作。为什么?

代码语言:javascript
复制
<Style x:Key="ABC" TargetType="{x:Type TextBlock}">
    <Style.Triggers>
        <Trigger Property ="IsMouseOver" Value="True">
            <Setter Property= "Foreground" Value="Black">
        </Trigger>
    </Style.Triggers>
</Style>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-20 14:38:22

您在本地为Foreground设置了TextBlock,因此Trigger设置器不能覆盖该设置。您需要使用样式设置器来设置初始前台:

代码语言:javascript
复制
<Style x:Key="ABC" TargetType="{x:Type TextBlock}">
  <Setter Property="Foreground" Value="White"/>
  <Style.Triggers>
    <Trigger Property ="IsMouseOver" Value="True">
        <Setter Property= "Foreground" Value="Black">
    </Trigger>
  </Style.Triggers>
</Style>

Foreground="White"应该从<TextBlock ...中删除。

了解有关依赖属性值优先的更多信息。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33239557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档