我有一个 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/