【发布时间】:2011-12-20 14:28:50
【问题描述】:
我想在我的 window.resources 中有一个 Style DataTrigger 可用于多个扩展器。 DataTrigger 绑定到我的 ViewModel 中的枚举值,并且基于枚举值,我希望折叠正确的扩展器。例如:如果枚举值设置为“A”,那么我只希望与类型“A”关联的扩展器可见,而其余扩展器则折叠起来。
我在想这样的事情:
<Style TargetType="{x:Type Expander}">
<Style.Triggers>
<DataTrigger Binding="{Binding Type}" Value="A">
// In here i would set the expander associated w/ "A" to Visible
// and have the rest of the expanders collapsed. Since TargetName is
// not allowed within a "Setter" property of a style, I am not sure on how to accomplish this.
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="B">
// Same concept as above
</DataTrigger>
</Style.Triggers>
</Style>
【问题讨论】:
-
有人可能会为您解答,但我认为 XAML 不会支持该级别的逻辑。它更像是直接通过屏幕指令。如果枚举值是通过 UI 控件设置的,那么您可以使用事件处理程序或将触发器放在各个扩展器上。
标签: .net wpf xaml datatrigger