fix: fix RoutedEvent register sample code.

This commit is contained in:
rabbitism 2022-09-20 01:03:48 +08:00
Родитель 739cd44e01
Коммит bdbdec87c7
1 изменённых файлов: 8 добавлений и 5 удалений

Просмотреть файл

@ -45,14 +45,17 @@ A routed event is a CLR event that is backed by an instance of the `RoutedEvent`
The following example shows the declaration for a custom `Tap` routed event, including the registration and exposure of the `RoutedEvent` identifier field and the `add` and `remove` implementations for the `Tap` CLR event.
```csharp
public static readonly RoutedEvent<RoutedEventArgs> TapEvent =
RoutedEvent.Register(nameof(Tap), RoutingStrategies.Bubble);
// Provide CLR accessors for the event
public event EventHandler<RoutedEventArgs> Tap
public class SampleControl: Control
{
public static readonly RoutedEvent<RoutedEventArgs> TapEvent =
RoutedEvent.Register<SampleControl, RoutedEventArgs>(nameof(Tap), RoutingStrategies.Bubble);
// Provide CLR accessors for the event
public event EventHandler<RoutedEventArgs> Tap
{
add => AddHandler(TapEvent, value);
remove => RemoveHandler(TapEvent, value);
}
}
```