I have a WPF MainWindow with my own RoutedEvent, which is raised when pushing the Enter key.
namespace ZK16
{
public partial class MainWindow : Window
{
public static readonly RoutedEvent CustomEvent = EventManager.RegisterRoutedEvent(
"Custom", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MainWindow));
public event RoutedEventHandler Custom
{
add { AddHandler(CustomEvent, value); }
remove { RemoveHandler(CustomEvent, value); }
}
void RaiseCustomEvent()
{
Debug.WriteLine("RaiseCustomEvent");
RoutedEventArgs newEventArgs = new RoutedEventArgs(MainWindow.CustomEvent);
RaiseEvent(newEventArgs);
}
public MainWindow()
{
InitializeComponent();
this.AddHandler(MainWindow.CustomEvent, new RoutedEventHandler(MyCustomHandler));
}
private void MyCustomHandler(object sender, RoutedEventArgs e)
{
Debug.WriteLine("In Eventhandler...");
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
RaiseCustomEvent();
}
In XAML I add a Label with an EventTrigger,
<Window x:Class="ZK16.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ZK16"
Title="MainWindow"
PreviewKeyDown="Window_PreviewKeyDown"
>
<Grid>
<Label Content="Hello World">
<Label.Triggers>
<EventTrigger RoutedEvent="local:MainWindow.Custom">
<BeginStoryboard>
<Storyboard Duration="00:00:1">
<DoubleAnimation From="6" To="25" Storyboard.TargetProperty="FontSize"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Label.Triggers>
</Label>
</Grid>
</Window>
but when raising the custom event, the EventTrigger does not fire on my event, but fires if e.g.
EventTrigger RoutedEvent="Loaded"
Can anybody tell me, what's wrong?