Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventSetter for non-routed event?

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?

like image 553
Marcus Avatar asked Nov 01 '11 22:11

Marcus


People also ask

Which of the following is routing strategy of routed events?

The routed event then routes to successive parent elements, invoking their event handlers in turn, until it reaches the element tree root. Most routed events use the bubbling routing strategy.

What is the exact difference between bubbling event and tunneling events?

The difference between the two, as the naming convention implies, is that a tunneling event will start at the highest node in the tree (probably the Window) and going down to the lowest child. A bubbling event will start at the child and then go upwards again.

What is event setter?

Event setters invoke the specified event handlers in response to events.


1 Answers

From the documentation:

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

(Also as noted in the comment, MouseDown is routed.)

like image 179
H.B. Avatar answered Oct 20 '22 01:10

H.B.