DataTrigger上枚举作为一个WPF风格的触发值 [英] DataTrigger on Enums as the trigger value on a WPF Style
问题描述
因此,这里就是我想要做一点简单地说,我只是要开始与code和它很可能会是有意义的。
So here's what I'm trying to do in a little nutshell, I'm just gonna start with code and it will most likely make sense.
<bl:InnerGlowBorder x:Name="glow"
InnerGlowColor="Teal">
<bl:InnerGlowBorder.Style>
<Style TargetType="bl:InnerGlowBorder">
<Style.Triggers>
<DataTrigger Binding="{Binding ViewUnitStatus}"
Value="UnitStatusModel.Pass">
<Setter Property="InnerGlowColor"
Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding ViewUnitStatus}"
Value="UnitStatusModel.Fail">
<Setter Property="InnerGlowColor"
Value="Red" />
</DataTrigger>
<DataTrigger Binding="{Binding ViewUnitStatus}"
Value="UnitStatusModel.Indeterminate">
<Setter Property="InnerGlowColor"
Value="Yellow" />
</DataTrigger>
<DataTrigger Binding="{Binding ViewUnitStatus}"
Value="UnitStatusModel.Warning">
<Setter Property="InnerGlowColor"
Value="Orange" />
</DataTrigger>
</Style.Triggers>
</Style>
</bl:InnerGlowBorder.Style>
</bl:InnerGlowBorder>
和枚举定义:
namespace SEL.MfgTestDev.ESS.ViewModel
{
public enum UnitStatusModel
{
Indeterminate,
Pass,
Fail,
Warning,
}
}
我缺少了一块,使这项工作?我发现在依赖对象的数据源枚举一些WPF的文章,我真的不喜欢这种解决方案,是不是有更多的东西简单,我可以在这里做什么?
Am I missing a piece to make this work? I've found some WPF articles on enums that rely on object data sources and I don't really like that solution, isn't there something more simple I can do here?
推荐答案
我已经找到了解决办法,这是很愚蠢的。
I have found the solution and it was quite silly.
样式设计作为一种可视化模板控制的,但它们被设计为视觉实施的基础,而不是作为一个BE-全/最终所有的可视化模型。
Styles are designed as a sort of visual template for a control, but they are designed as a base for visual implementation, not as a be-all/end-all visual model.
这样一来,我有一种情况,就是我的模板决定什么InnerGlowColor应该的。然而,通过应用属性InnerGlowColor =蒂尔的元素,我创建了有效的覆盖,无视我的视觉风格。解决的办法是简单地删除元素声明扶养属性。
As a result, I had a situation in which my template dictated what the InnerGlowColor should be. However, by applying the attribute InnerGlowColor="Teal" to the element, I've created an override in effect, ignoring my visual style. The solution was to simply remove the dependancy property in the element declaration.
这篇关于DataTrigger上枚举作为一个WPF风格的触发值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!