Changing TextBlock.Text in trigger does not work

I have the following code in my opinion:

<Style x:Key="documentFileNameStyle">
    <Setter Property="TextBlock.Foreground" Value="Gray"/>
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Untitled}" Value="True">
            <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 the string did not work. TextBlock.FontStyle changes to italics, so the whole trigger works correctly. What's wrong?

+3
source share
1 answer

Local assignment of properties has a higher priority than setting values ​​in triggers.

You also use Binding (Path = FileName) to set the TextBlock text property. Therefore, changing the text in triggers does not affect the Property.

. "FileName", "no file name", " " "".

+9

Source: https://habr.com/ru/post/1747820/


All Articles