WPF 触发器和样式
我有一个 UserControl,在资源部分我有这样的代码,
<Style TargetType="{x:Type Viewbox}">
<Style.Triggers>
<Trigger Property="Viewbox.IsMouseOver" Value="True">
<Setter Property="Viewbox.Effect" >
<Setter.Value>
<DropShadowEffect Color="DarkGray" Direction="45" BlurRadius="30"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
这适用于我在此控件中拥有的 ViewBox,
但是当我
<Viewbox.Triggers>
<Trigger Property="Viewbox.IsMouseOver" Value="True">
<Setter Property="Viewbox.Effect" >
<Setter.Value>
<DropShadowEffect></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
</Viewbox.Triggers>
在 View Box 中执行此操作时,我会收到错误......
有没有办法将本地触发器添加到ViewBox 不使用样式?
I have a UserControl, in the Resources section I have code like
<Style TargetType="{x:Type Viewbox}">
<Style.Triggers>
<Trigger Property="Viewbox.IsMouseOver" Value="True">
<Setter Property="Viewbox.Effect" >
<Setter.Value>
<DropShadowEffect Color="DarkGray" Direction="45" BlurRadius="30"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
SO this works for the ViewBox that I have in this control,
but when I do
<Viewbox.Triggers>
<Trigger Property="Viewbox.IsMouseOver" Value="True">
<Setter Property="Viewbox.Effect" >
<Setter.Value>
<DropShadowEffect></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
</Viewbox.Triggers>
within the View Box I get errors....
Is there a way to add local triggers to the ViewBox without using a Style?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 MSDN
From MSDN
FrameworkElements 与样式和模板的触发器集合接受不同类型的触发器。对于 FrameworkElement.Triggers,您只能使用 EventTrigger,通常用于启动动画。 Style、ControlTemplate 和 DataTemplate 触发器集合可以使用您正在使用的更常见的触发器和数据触发器。这是一个奇怪的设置,总是让人感觉像是一个未完成的功能。您可以更改代码以使用 Storyboard 从 EventTrigger 为 DropShadowEffect 上的属性设置动画,或者仅使用 Style 方法。
The Triggers collections of FrameworkElements vs Styles and Templates accept different types of triggers. For FrameworkElement.Triggers you can only use EventTrigger, commonly used to start animations. Style, ControlTemplate, and DataTemplate Triggers collections can use the more common Trigger and DataTrigger like you're using. It's an odd setup that's always sort of felt like an unfinished feature. You could change your code to use a Storyboard to animate properties on the DropShadowEffect from an EventTrigger or just use the Style approach.