gpt4 book ai didi

wpf - 用于非路由事件的 EventSetter?

转载 作者:行者123 更新时间:2023-12-04 14:49:57 28 4
gpt4 key购买 nike

我有一个 Label我正在尝试更改 MouseDown用户是否使用 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>

但是,与 this相反发布,我将无法使用,因为 MouseDown不是路由事件。我仍然收到 System.Windows.EventSetter.Event错误: {"Value cannot be null.\r\nParameter name: value"} .

所以我的问题是,有没有办法使用触发器来设置非路由事件?

最佳答案

来自 documentation :

Note that only Style.Setters supports EventSetter objects. Triggers (TriggerBase and derived classes) do not support EventSetter.



(同样如评论中所述, MouseDown 被路由。)

关于wpf - 用于非路由事件的 EventSetter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973606/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com