我可以让 WPF 样式优先于本地值吗?

编程入门 行业动态 更新时间:2024-10-25 19:35:22
本文介绍了我可以让 WPF 样式优先于本地值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的 WPF 项目中创建了一个布尔附加属性,并且我希望将此属性设置为 true 的元素以某种方式显示,而不管在 XAML 中设置的任何本地本地值如何.

I have created a boolean attached property in my WPF project, and I want elements with this property set to true to display a certain way, regardless of any local local values that have been set in the XAML.

从 文档 中,我了解到默认情况下,本地值优先于样式设置器和样式触发器.是否可以创建一个优先于本地值的样式触发器?

From the documentation, I understand that by default, local values take precedence over both style setters and style triggers. Is it possible to create a style trigger that takes precedence over local values?

推荐答案

使用 Erti-Chris Eelmaa 在他对我的问题的评论中提到的技术,我最终创建了一个成功的动画:

Using the technique mentioned by Erti-Chris Eelmaa in his comment on my question, I ended up creating an animation which did the trick:

<Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="my:Ext.IsReadOnly" Value="True"> <Trigger.EnterActions> <BeginStoryboard Name="IsReadOnly"> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.IsEnabled)" Duration="0:0:0"> <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" /> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <RemoveStoryboard BeginStoryboardName="IsReadOnly" /> </Trigger.ExitActions> </Trigger> </Style.Triggers> </Style>

这优先于 Button.IsEnabled 的任何本地值.

This takes precedence over any local value for Button.IsEnabled.

更多推荐

我可以让 WPF 样式优先于本地值吗?

本文发布于:2023-11-06 14:39:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!