下面的datatrigger不起作用。任何想法爲什麼不呢?
我檢查後面的代碼,在兩種情況下LineCount分別是1.
但是,當我將值更改爲「-1」觸發器正在工作。
那麼爲什麼LineCount總是-1?DataTrigger不能正常工作(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(framework 3.5)中設置這個屬性。 – Gerard
在代碼中通過'this.TextInfo.TextChanged + = TextInfo_TextChanged;'它的工作原理,我想這比創建附加的依賴屬性要容易一些。 – Gerard