I've define a custom RoutedEvent
and use it in EventTrigger
. But VS keep showing error.
Event definition:
public event RoutedEventHandler Lock
{
add { AddHandler(LockEvent, value); }
remove { RemoveHandler(LockEvent, value); }
}
public static readonly RoutedEvent LockEvent =
EventManager.RegisterRoutedEvent("Lock", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyControl));
Event usage:
<UserControl.Triggers>
<EventTrigger RoutedEvent="{x:Static local:MyControl.LockEvent}">
<BeginStoryboard/>
</EventTrigger>
<UserControl.Triggers>
The code can be run but there is always a squiggly line under RoutedEvent="{x:Static local:MyControl.LockEvent}"
and giving error:
Value cannot be null.
Parameter name: value
How can I fix this error? (or how to ignore it without Suppress XAML Designer errors?)
If I use the RoutedEvent like this:
<EventTrigger RoutedEvent="local:MyControl.Lock">
, another error occurs:The event 'Lock' is not a RoutedEvent.
You reference an event like this using xmlnsAlias:ControlType.Event.
And you should add an event, compile then try and reference it.
Edit: Let's make this thing actually animate something and end to end it.
This works for me:
and
This works whatever platform I target and animates the usercontrol background to green.