Sel*_*don 3 wpf styles datatrigger textblock
我在我的视图中有下一个代码:
<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>
Run Code Online (Sandbox Code Playgroud)
但是将TextBlock.Text设置为字符串不起作用.TextBlock.FontStyle更改为Italic,因此整个触发器正常工作.怎么了?
属性的本地分配优先于在触发器中设置值.
您还使用Binding(Path = FileName)来设置TextBlock的Text-Property.因此,更改触发器中的文本不会影响该属性.
正如您使用Binding一样.如果Property"Untitled"为"true",我会更改Property"FileName"以返回"no file name".
归档时间: |
|
查看次数: |
4358 次 |
最近记录: |