Remarks: This is the base class for platform handlers. It is used to help wire up events and provide base functionality of a widget.
TControlType of the platform-specific object
TWidgetType of widget the handler is for where Widget
This example shows how to implement a platform handler for a widget
// override the class and implement widget-specific interface
public MyWidgetHandler : WidgetHandler<MyPlatformControl, MyWidget>, IMyWidget
{
	// implement IStaticWidget's properties and methods
}
WidgetHandler<T, W>

Properties

Callback

protected object Callback { get; }
Gets the callback object for the control
inherited fromWidgetHandler<TWidget>
Remarks: This object is typically a single static instance that is used by the platform handlers to call private or protected methods on the widget, such as protected event methods e.g. protected virtual void OnClick(EventArgs e)
The callback.

Connector

#
protected WidgetHandler<TControl, TWidget>.WeakConnector Connector { get; }
Gets a weak connector class to hook up events to the underlying control
Remarks: Some frameworks (e.g. gtk, monomac, ios, android) keep track of references in a way that leak objects when there is a circular reference between the control and the handler. This is the case when registering events from the control to a method implemented in the handler. This instance can be used to connect the objects together using a weak reference to the handler, allowing controls to be garbage collected.
The connector instance

Control

#
public TControl Control { get; set; }
Gets or sets the platform-specific control object

DisposeControl

#
protected virtual bool DisposeControl { get; }
Gets a value indicating that control should automatically be disposed when this widget is disposed

HasControl

#
public bool HasControl { get; }
Gets a value indicating whether this instance has a Control instance.

NativeHandle

public virtual nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidgetHandler<TWidget>

Widget

public TWidget Widget { get; }
Gets the widget that this platform handler is attached to
inherited fromWidgetHandler<TWidget>

Methods

AttachEvent

public virtual void AttachEvent(string id)
Attaches the specified event to the platform-specific control
inherited fromWidgetHandler<TWidget>
Remarks: Implementors should override this method to handle any events that the widget supports. Ensure to call the base class' implementation if the event is not one the specific widget supports, so the base class' events can be handled as well.
id (string)Identifier of the event

CreateConnector

#
protected virtual WidgetHandler<TControl, TWidget>.WeakConnector CreateConnector()
Creates the event connector for this control
Remarks: This creates the weak connector to use for event registration and other purposes.
Connector

CreateControl

#
protected virtual TControl CreateControl()
Creates the control if not already set.
Remarks: Override this to create the control instance for the handler. This makes it easy to extend existing handler implementations with different control implementations. Some platforms (e.g. Mac) require subclasses to implement/override functionality.
The control.

DetachEvent

public virtual bool DetachEvent(string id)
Detaches an event from the platform-specific control, undoing WidgetHandler<TWidget>.AttachEvent(string).
inherited fromWidgetHandler<TWidget>
Remarks: Implementors can override this for events that hold onto something worth giving back while they are attached, such as a system wide hook. Most events cost nothing to leave attached for the life of the widget, which is why the default is to refuse. Only reached for events whose remove accessor uses PropertyStore.RemoveHandlerEvent(string, Delegate), and never for an event that is attached because the widget overrides its On[Event] method.
id (string)Identifier of the event
True if the event was detached, false if this platform can't detach it, in which case it stays attached and won't be attached again on a later subscription.

Dispose

#
protected override void Dispose(bool disposing)
Disposes this widget and the associated control if DisposeControl is true

GetControl

#
public static TControl GetControl(TWidget widget)
Gets the platform-specific control object of the specified widget using this handler
Remarks: The widget must be using a handler that returns the same control. This can be used very easily by platform code:
MyControl mycontrol;
var platformControl = MyControlHandler.GetControl(mycontrol);
Note that even if the specified handler is used, the control might not actually be using that handler. This method will still work as long as the handler implements using the same base platform-specific control.
widget (TWidget)The widget to get the platform-specific control from
The platform-specific control used for the specified widget

HandleEvent

public void HandleEvent(string id, bool defaultEvent = false)
Called to handle a specific event
inherited fromWidgetHandler<TWidget>
Remarks: Most events are late bound by this method. Instead of wiring all events, this will be called with an event string that is defined by the control. This is called automatically when attaching to events, but must be called manually when users of the control only override the event's On... method. Override the WidgetHandler<TWidget>.AttachEvent(string) to attach your events
id (string)ID of the event to handle
defaultEvent (bool = false)True if the event is default (e.g. overridden or via an event handler subscription)
HandleEvent

Initialize

protected virtual void Initialize()
Called to initialize this widget after it has been constructed
inherited fromWidgetHandler<TWidget>
Remarks: Override this to initialize any of the platform objects. This is called in the widget constructor, after all of the widget's constructor code has been called.

IsEventHandled

public bool IsEventHandled(string id)
Gets a value indicating that the specified event is handled
inherited fromWidgetHandler<TWidget>
id (string)Identifier of the event
True if the event is handled, otherwise false

OnInitializeComplete

protected virtual void OnInitializeComplete()
Called after initialization is complete
inherited fromWidgetHandler<TWidget>
Remarks: Override this to perform any logic after the handler is fully initialized, but before returning from the construction of the widget. This by default applies the any styles for the handler.

UnhandleEvent

public void UnhandleEvent(string id)
Called when the last subscriber to an event has been removed, giving WidgetHandler<TWidget>.DetachEvent(string) the chance to stop listening for it.
inherited fromWidgetHandler<TWidget>