winrt::event struct template (C++/WinRT)
A type that you can use to declare and implement an event of a specified delegate type. Subscribers pass their event-handling delegates to an event; the event registers those delegates in a collection; then, when it is raised, the event invokes its registered delegates in turn so that subscribers can handle the event. For more info about authoring events, and code examples, see Author events in C++/WinRT.
If you need events internal to your project, and not limited to Windows Runtime types, then use event<winrt::delegate>. For more info, see Parameterized delegates, simple signals, and callbacks within a project.
For more info about handling events, and code examples, see Handle events by using delegates in C++/WinRT.
template <typename Delegate> struct event
The type of delegate that can register to handle the event.
Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Member type aliases
|event::delegate_type||A synonym for the
|event::event constructor||Initializes a new instance of the event struct.|
|event::add function||Registers a delegate with the event object.|
|event::remove function||Revokes a delegate's registration from the event object.|
|event::operator() (function call operator)||Invokes all of the event object's registered delegates with the provided arguments.|
|event::operator bool||Checks whether the event object has any delegates registered with it.|
Initializes a new instance of the event struct.
Registers a delegate with the event object.
winrt::event_token add(Delegate const& delegate);
A delegate to register with the event object.
A winrt::event_token that can subsequently be used to revoke the delegate's registration.
event::operator() (function call operator)
Invokes all of the event object's registered delegates with the provided arguments.
template<typename... Arg> void operator()(Arg const&... args)
A variadic template parameter pack containing the types of the parameters that the delegate is passed when it's called.
A variable argument list containing the arguments that the delegate is passed when it's called.
Checks whether the event object has any delegates registered with it.
explicit operator bool() const noexcept;
true if the event object has any registered delegates, otherwise
Revokes a delegate's registration from the event object.
void remove(winrt::event_token const token);
A winrt::event_token that identifies the delegate whose registration to revoke.