我想有一个风格DataTrigger我window.resources可用于多种扩展里面一个数据触发。 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是要支持逻辑的那个级别。它更像是屏幕指令的直接传球。如果Enum值是通过UI控件设置的,那么你可以通过事件处理程序来完成它,或者在各个扩展程序上放置触发器。 – Paparazzi