-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Description
When I create a RoutedEvent and try any routing mode (except Direct), the event never ends up firing in WPF.
Reproduction Steps
<Border x:Name="MainBorder">
<Border.Resources>
<Storyboard x:Key="ShowStoryboard">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.8"/>
<DoubleAnimation Storyboard.TargetProperty="Height" From="10" To="350" Duration="0:0:0.3"/>
</Storyboard>
<Storyboard x:Key="HideStoryboard">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.4"/>
<DoubleAnimation Storyboard.TargetProperty="Height" From="350" To="10" Duration="0:0:0.5"/>
</Storyboard>
</Border.Resources>
<Border.Triggers>
<EventTrigger RoutedEvent="local:MainWindow.ShutdownStarted">
<BeginStoryboard Storyboard="{StaticResource HideStoryboard}"/>
</EventTrigger>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource ShowStoryboard}"/>
</EventTrigger>
</Border.Triggers>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Opacity" Value="0"/>
<Setter Property="Height" Value="10"/>
<Setter Property="Width" Value="450"/>
</Style>
</Border.Style>
public static readonly RoutedEvent ShutdownStartedEvent = EventManager.RegisterRoutedEvent(
nameof(ShutdownStarted),
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(MainWindow)
);
public event RoutedEventHandler ShutdownStarted {
add { AddHandler(ShutdownStartedEvent, value); }
remove { RemoveHandler(ShutdownStartedEvent, value); }
}
RaiseEvent(new RoutedEventArgs(ShutdownEventStarted));
Expected behavior
When I raise the event, the border should fade out. It does not.
Actual behavior
The border doesn't change.
Regression?
This code work fine in .net 4.8 and WPF
Known Workarounds
You have to call RaiseEvent on the actual element that's listening for the event.
In this case, I have to call RaiseEvent(new RoutedEventArgs(ShutdownEventStarted)) to get the Trigger to work.
Impact
Maybe I misunderstand the state of dotnet and wpf, but I had assumed it was production ready. This is a pretty big issue I think.
Configuration
dotnet core 8
Windows 11
Visual Studio 17.9.0 Preview 3.0
x64
Other information
Same problem happens with or without visual studio and with or without debugging.