Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing TextBlock.Text in trigger didn't work

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">
            <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?

like image 586
Seldon Avatar asked Jan 28 '26 08:01

Seldon


1 Answers

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".

like image 74
Jehof Avatar answered Jan 30 '26 22:01

Jehof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!