Bubbling & Tunneling
Bubbling: 일반적으로 사용되는 방식, from Child to Parent until Root!
Tunneling: 접두사로 Preview가 붙는 이벤트, from Root to Child.

더이상 이벤트가 전파되지 않도록 막는 방법
void MyEventHandler(object sender, RoutedEventArgs e) { e.Handled = true; }
Custom Routed Event
MSDN
public class MyButtonSimple: Button { // Create a custom routed event by first registering a RoutedEventID // This event uses the bubbling routing strategy public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent( "Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple)); // Provide CLR accessors for the event public event RoutedEventHandler Tap { add { AddHandler(TapEvent, value); } remove { RemoveHandler(TapEvent, value); } } // This method raises the Tap event void RaiseTapEvent() { var newEventArgs = new RoutedEventArgs(MyButtonSimple.TapEvent); RaiseEvent(newEventArgs); } // For demonstration purposes we raise the event when the MyButtonSimple is clicked protected override void OnClick() { RaiseTapEvent(); } }
'.NET > WPF' 카테고리의 다른 글
| Adorner (0) | 2021.08.15 |
|---|---|
| WPF Graphics Rendering (0) | 2021.08.15 |
| ScrollViewer Tips (0) | 2021.08.15 |
| Save Canvas as an Image (0) | 2021.08.15 |
| LayoutTransform vs. RenderTransform (0) | 2021.08.15 |