tags:

views:

15

answers:

1

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?

A: 

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

Jehof
Thank you, setting Text="{Binding Path=FileName}" in style instead of local assignment fixed problem.
Seldon