【发布时间】:2013-11-01 13:20:30
【问题描述】:
下面的数据触发器不工作。知道为什么不?
我检查了后面的代码,两种情况下的 LineCount 分别为 1 和 4。
但是当我将值更改为“-1”时,触发器正在工作。
那么为什么 LineCount 总是 -1?
<TextBox x:Name="TextInfo" TextWrapping="Wrap" Text="Information" HorizontalAlignment="Stretch" Foreground="OrangeRed">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding LineCount, ElementName=TextInfo}" Value="4">
<Setter Property="Background" Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding LineCount, ElementName=TextInfo}" Value="1">
<Setter Property="Background" Value="PowderBlue" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
【问题讨论】:
-
我刚刚在 MSDN TextBox.LineCount 属性中看到:不能在 xaml(框架 3.5)中设置此属性。
-
在代码中通过
this.TextInfo.TextChanged += TextInfo_TextChanged;工作,我想这比创建附加的依赖属性要容易一些。
标签: wpf datatrigger