![]() |
正直的大蒜 · python ...· 1 年前 · |
![]() |
谦虚好学的消防车 · Spark--java.util.NoSuc ...· 1 年前 · |
![]() |
精明的蘑菇 · tomcat jmx port 1099 ...· 1 年前 · |
为什么我不能这样写代码呢?
<Border Width="130" Height="70">
<Border.Triggers>
<DataTrigger Binding="{Binding Path=CurrentStatus}" Value="0">
<Setter Property="Style" Value="{StaticResource ResourceKey=ListBoxItemBorder}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=CurrentStatus}" Value="200">
<Setter Property="Style" Value="{StaticResource ResourceKey=ListBoxItemBorderInactive}"/>
</DataTrigger>
</Border.Triggers>
</Border>
我得到了这个错误
Failed object initialization (ISupportInitialize.EndInit).
Triggers collection members must be of type EventTrigger.
Error at object '4_T' in markup file
我做错了什么?请帮帮我。
发布于 2010-08-27 00:59:15
Abe是正确的,并很好地解释了这些限制。您可能需要考虑的一件事是:
而不是有两种边框样式,并试图根据触发器在它们之间进行选择...
在你的边框上使用一个单一的样式,这个样式的setter代表你的“正常”外观。此样式还包含您的DataTrigger,并且您的DataTrigger有一个setter集合,这些setter实际上代表您的第二个样式(当此触发器的计算结果为真时,这些setter的优先级高于标准setter!
编辑:
像这样的东西-
<Style TargetType="Border" x:Key="BorderStyle">
<!-- These setters are the same as your normal style when none of your triggers are true -->
<Setter Property="BorderBrush" Value="Black" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CurrentStatus}" Value="0">
<!-- These setters are the same as your ListBoxItemBorder style -->
<Setter Property="BorderBrush" Value="Green" />
</DataTrigger>