3

私の見解には次のコードがあります:

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

しかし、TextBlock.Textを文字列に設定しても機能しませんでした。TextBlock.FontStyleが斜体に変更されるため、トリガー全体が正しく機能します。なにが問題ですか?

4

1 に答える 1

9

プロパティのローカル割り当ては、トリガーに値を設定するよりも優先されます。

また、Binding(Path = FileName)を使用してTextBlockのText-Propertyを設定しています。したがって、トリガーのテキストを変更しても、プロパティには影響しません。

バインディングを使用しているため。プロパティ「Untitled」が「true」の場合、プロパティ「FileName」を変更して「nofilename」を返します。

于 2010-05-31T09:54:38.787 に答える