TextBlock Text property can't be set via style trigger if non-empty - why?

你说的曾经没有我的故事 提交于 2019-12-07 06:02:44

问题


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>

But, if the Text attribute is missing:

 <Grid>
    <TextBlock/>
</Grid>

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


回答1:


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.

see

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



来源:https://stackoverflow.com/questions/812822/textblock-text-property-cant-be-set-via-style-trigger-if-non-empty-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!