Last active
March 18, 2019 09:25
-
-
Save wi7a1ian/afe4e9b8091fbdabee8c79211bec6e80 to your computer and use it in GitHub Desktop.
Example of RoutedEvent #wpf #csharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register the routed event | |
public static readonly RoutedEvent SelectedEvent = | |
EventManager.RegisterRoutedEvent( "Selected", RoutingStrategy.Bubble, | |
typeof(RoutedEventHandler), typeof(MyCustomControl)); | |
// .NET wrapper | |
public event RoutedEventHandler Selected | |
{ | |
add { AddHandler(SelectedEvent, value); } | |
remove { RemoveHandler(SelectedEvent, value); } | |
} | |
// Raise the routed event "selected" | |
RaiseEvent(new RoutedEventArgs(MyCustomControl.SelectedEvent)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class = "WPFRoutedEvents.MainWindow" | |
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" | |
Title = "MainWindow" Height = "450" Width = "604" MyCustomControl.Selected = "Window_Selected" > | |
<Grid> | |
<StackPanel Margin = "20" MyCustomControl.Selected = "StackPanel_Selected"> | |
<local:MyCustomControl Selected = "MyCustomControl_Selected" /> | |
</StackPanel> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment