I mean if i have some custom event with bubbling strategy, then who must declare preview event and who must care about its raising? Me or WPF?
for example I has class with event
public class WindowControl : ContentControl
{
public static readonly RoutedEvent StateChangedEvent;
static WindowControl()
{
WindowControl.StateChangedEvent = EventManager.RegisterRoutedEvent("StateChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(WindowControl));
}
public event RoutedEventHandler StateChanged
{
add { base.AddHandler(WindowControl.StateChangedEvent, value); }
remove { base.RemoveHandler(WindowControl.StateChangedEvent, value); }
}
private void RaiseStateChangedEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(WindowControl.PreviewStateChangedEvent, this);
this.RaiseEvent(newEventArgs);
}
}
I suppose that as someone wants to subscribe on preview event of my control, I must declare it too, except the only thing that it would have tunneling strategy. So question is - should I generate it by myself and where? I tried so (suppose we have PreviewStateChanged declared):
private void RaiseStateChangedEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(WindowControl.PreviewStateChangedEvent, this);
this.RaiseEvent(newEventArgs);
newEventArgs = new RoutedEventArgs(WindowControl.StateChangedEvent, this);
this.RaiseEvent(newEventArgs);
}
It raises ok, but despite that I change e.Handeled = true StateChangedEvent is being fired. Thus I conclude that WPF routing system doesn't treat them as linked events. Or maybe (and more probably) I'm doing something wrong -)
So I need some help -)