我在我的 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 样式优先于本地值吗?
发布评论