mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 00:56:03 +02:00
* Add article, redirects, toc * Update dotnet-desktop-guide/net/wpf/events/how-to-create-a-custom-routed-event.md Co-authored-by: Andy (Steve) De George <[email protected]> * Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/csharp/CodeSample.csproj Co-authored-by: Andy (Steve) De George <[email protected]> * Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/vb/CodeSampleVb.vbproj Co-authored-by: Andy (Steve) De George <[email protected]> * Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/WpfControlLibraryCsharp/WpfControlLibrary.csproj Co-authored-by: Andy (Steve) De George <[email protected]> * Use local project references Co-authored-by: Andy (Steve) De George <[email protected]>
43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using System.Diagnostics;
|
|
using System.Windows;
|
|
|
|
namespace CodeSample
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Assign an event handler to the CustomButton using the '+=' operator.
|
|
// customButton.ConditionalClick += Handler_ConditionalClick;
|
|
|
|
// Assign an event handler to the CustomButton using the AddHandler method.
|
|
// customButton.AddHandler(WpfControl.CustomButton.ConditionalClickEvent,
|
|
// new RoutedEventHandler(Handler_ConditionalClick));
|
|
|
|
// Assign an event handler to the StackPanel using the AddHandler method.
|
|
// StackPanel1.AddHandler(WpfControl.CustomButton.ConditionalClickEvent,
|
|
// new RoutedEventHandler(Handler_ConditionalClick));
|
|
}
|
|
|
|
//<EventHandler>
|
|
// The ConditionalClick event handler.
|
|
private void Handler_ConditionalClick(object sender, RoutedEventArgs e)
|
|
{
|
|
string senderName = ((FrameworkElement)sender).Name;
|
|
string sourceName = ((FrameworkElement)e.Source).Name;
|
|
|
|
Debug.WriteLine($"Routed event handler attached to {senderName}, " +
|
|
$"triggered by the ConditionalClick routed event raised on {sourceName}.");
|
|
}
|
|
|
|
// Debug output when CustomButton is clicked:
|
|
// Routed event handler attached to CustomButton,
|
|
// triggered by the ConditionalClick routed event raised on CustomButton.
|
|
// Routed event handler attached to StackPanel1,
|
|
// triggered by the ConditionalClick routed event raised on CustomButton.
|
|
//</EventHandler>
|
|
}
|
|
}
|