非路由事件的 EventSetter?
我有一个 Label
,我正在尝试使用 Trigger
更改用户是否登录的 MouseDown
事件。
<Label x:Name="lblSave" MouseDown="lblSave_MouseDown" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" ToolTip="Save Files" Width="25" Height="25" Margin="0, 0, 5, 0" >
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Background" Value="{DynamicResource ResourceKey=saveIcon}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static sec:Security.Instance}, Path=IsLoggedIn}" Value="False">
<Setter Property="Background" Value="{DynamicResource ResourceKey=readonlyIcon}" />
<EventSetter Event="MouseDown" Handler="lblNoAccess_MouseDown" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
但是,与这篇文章相反,我所拥有的不起作用,因为 MouseDown
不是路由事件。我仍然收到 System.Windows.EventSetter.Event
错误:{"Value can not be null.\r\nParameter name: value"}
。
所以我的问题是,有没有办法使用触发器来设置非路由事件?
I have a Label
that I'm trying to change the MouseDown
event for if a user is logged in or not by using a Trigger
.
<Label x:Name="lblSave" MouseDown="lblSave_MouseDown" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" ToolTip="Save Files" Width="25" Height="25" Margin="0, 0, 5, 0" >
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Background" Value="{DynamicResource ResourceKey=saveIcon}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static sec:Security.Instance}, Path=IsLoggedIn}" Value="False">
<Setter Property="Background" Value="{DynamicResource ResourceKey=readonlyIcon}" />
<EventSetter Event="MouseDown" Handler="lblNoAccess_MouseDown" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
But, contrary to this post, what I have won't work because MouseDown
is not a routed event. I'm still getting the System.Windows.EventSetter.Event
error: {"Value cannot be null.\r\nParameter name: value"}
.
So my question is, is there a way to use a trigger to set non-routed events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像 HB 所说的那样,您不能在 Triggers 集合中使用 EventSetter,您应该检查事件处理程序是否已记录并执行正确的代码,这个解决方案不适合您吗?
Like H.B. said you can't use EventSetter in a Triggers collection, you should check in the event handler if it is logged or not and execute the right code, doesn't this solution work for you?
来自文档:
(也如评论中所述,
MouseDown
已路由。)From the documentation:
(Also as noted in the comment,
MouseDown
is routed.)