枚举上的 DataTrigger 作为 WPF 样式上的触发器值
简而言之,这就是我想做的事情,我将从代码开始,它很可能是有意义的。
<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 文章,但我不太喜欢该解决方案,难道我可以在这里做一些更简单的事情吗?
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>
And the enum definition:
namespace SEL.MfgTestDev.ESS.ViewModel
{
public enum UnitStatusModel
{
Indeterminate,
Pass,
Fail,
Warning,
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到了解决方案,但它非常愚蠢。
样式被设计为控件的一种视觉模板,但它们被设计为视觉实现的基础,而不是作为全部/最终的视觉模型。
结果,我遇到了这样的情况:我的模板决定了 InnerGlowColor 应该是什么。但是,通过将属性 InnerGlowColor="Teal" 应用于元素,我实际上创建了一个覆盖,忽略了我的视觉样式。解决方案是简单地删除元素声明中的依赖属性。
I have found the solution and it was quite silly.
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.
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.