Class handler for Loaded event is not always called
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: 3.0.0-preview8-28379-02
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
I want to document a "well known bug" so it can be fixed in the future (it had a rejected connect issue but the site is no longer available)
**Problem description:**
Registering a class handler for the `Loaded` event will not raise the event unless someone else also subscribes an instance handler on a particular instance. Class handlers for other events (e.g. Unloaded or Click) don't seem to have this problem.
**Actual behavior:**
Class handlers for the Loaded event are only raised if instance handlers are also subscribed.
**Expected behavior:**
Class handlers for the Loaded event should always be raised, like it is done for other events.
**Minimal repro:**
```xaml
```
```cs
using System.Windows;
using System.Windows.Controls;
namespace WpfAppBugRepro1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void InstanceHandler(object sender, RoutedEventArgs e)
{
var control = (Label)sender;
control.Content = (string)control.Content + " [Instance Handler called] ";
}
}
public class LabelWithClassHandler : Label
{
static LabelWithClassHandler()
{
EventManager.RegisterClassHandler(typeof(LabelWithClassHandler), LoadedEvent, new RoutedEventHandler(ClassHandler));
}
private static void ClassHandler(object sender, RoutedEventArgs e)
{
var control = (Label)sender;
control.Content = (string)control.Content + " [Class Handler called] ";
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.