UWP: Simple Events
Thursday, July 19, 2018
Notes [07/19/2018] Note: This post refers to the library Microsoft.NETCore.UniversalWindowsPlatform, version 6.2.0-Preview1-26502-02.
Events Some problems are just made so much easier in XAML based apps if you use the Event pub/sub model.
We’ll structure our events the way the excellent Template10 does:
One event One EventRaised method Untyped Events These events carry no information aside form the fact that it occurred.
In the class that the event originates from:
public class MyEventPublisherClass { /* This the event that will be subscribed to. */ public event EventHandler MyEvent; /* This is a convenience function that calls the event. */ void RaiseMyEvent() => MyEvent?.Invoke(this, new EventArgs { }); } This is an untyped event, so we use the Event version of an empty constructor with the new EventArgs {} syntax. The base EventArgs class contains no other fields.
…