开发者

Changing TextBlock.Text in trigger didn't work

开发者 https://www.devze.com 2023-01-01 09:23 出处:网络
I have the next code in my view: <Style x:Key=\"documentFileNameStyle\"> <Setter Property=\"TextBlock.Foreground\" Value=\"Gray\"/>

I have the next code in my view:

<Style x:Key="documentFileNameStyle">
    <Setter Property="TextBlock.Foreground" Value="Gray"/>
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Untitled}" Value="True">
          开发者_StackOverflow中文版  <Setter Property="TextBlock.FontStyle" Value="Italic"/>
            <Setter Property="TextBlock.Text" Value="no file name"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

<DataTemplate x:Key="documentTemplate">            
    <TextBlock Text="{Binding Path=FileName}" Style="{StaticResource documentFileNameStyle}"/>                                
</DataTemplate>

But setting TextBlock.Text to a string didn't work. TextBlock.FontStyle changes to Italic, so whole trigger works properly. What is wrong?


Local assignment of Properties has a higher precedence than setting the values in triggers.

Also you are using Binding (Path=FileName) to set the Text-Property of the TextBlock. So changing the Text in Triggers doesn´t effect the Property.

As you are using Binding. I would change the Property "FileName" to return "no file name" if the Property "Untitled" is "true".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号