TextBlock如果非空,则无法通过样式触发器设置Text属性-为什么? [英] TextBlock Text property can't be set via style trigger if non-empty - why?

查看:123
本文介绍了TextBlock如果非空,则无法通过样式触发器设置Text属性-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下XAML无效(鼠标悬停时,文本不会更改):

The XAML below does not work (the text does not change when mousing over):

<Window.Resources>
    <Style TargetType="TextBlock">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Text" Value="hover"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid>
    <TextBlock Text="original"/>
</Grid>

但是,如果缺少Text属性:

But, if the Text attribute is missing:

 <Grid>
    <TextBlock/>
</Grid>

鼠标悬停时,文本确实会更改。有人知道这背后的理论吗?

The text does change on mouse over. Anybody knows the theory behind this?

推荐答案

这是一个DependencyProperty优先级问题,实际上您将属性设置为:

It's a DependencyProperty precedence issue, when you actually set the property as in:

<TextBlock Text="original"/>

优先于触发器中设置的值。

that takes precedence over the value set in the trigger.

请参见

http://msdn.microsoft.com/en-us/library/ms743230.aspx

这篇关于TextBlock如果非空,则无法通过样式触发器设置Text属性-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆