2010-05-31 82 views
3

我有我的看法下一个代码:在触发更改TextBlock.Text没有工作

<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更改为斜体,因此整个触发器正常工作。哪里不对?

回答

9

属性的本地分配比设置触发器中的值具有更高的优先级。

此外,您正在使用绑定(Path = FileName)来设置TextBlock的Text-Property。因此,更改触发器中的文本不会影响该属性。

正如您使用绑定。如果属性“无标题”为“真”,我将更改属性“文件名”以返回“无文件名”。

+0

谢谢,在样式中设置Text =“{Binding Path = FileName}”,而不是本地分配固定的问题。 – Seldon 2010-05-31 09:59:27