Click or drag to resize

WidgetHandlerTControl, TWidget, TCallback Class

Widget handler with type-specific callback
Inheritance Hierarchy
SystemObject
  EtoWidgetHandlerTWidget
    EtoWidgetHandlerTControl, TWidget
      EtoWidgetHandlerTControl, TWidget, TCallback
        Eto.FormsThemedControlHandlerTControl, TWidget, TCallback
        Eto.Forms.ThemedControlsThemedAboutDialogHandler
        Eto.Forms.ThemedControlsThemedSegmentedItemHandlerTWidget, TCallback

Namespace:  Eto
Assembly:  Eto (in Eto.dll) Version: 2.5.3-dev
Syntax
public abstract class WidgetHandler<TControl, TWidget, TCallback> : WidgetHandler<TControl, TWidget>
where TWidget : Widget

Type Parameters

TControl
Type of the platform-specific object
TWidget
Type of widget the handler is for
TCallback
Type of the callback

The WidgetHandlerTControl, TWidget, TCallback type exposes the following members.

Constructors
  NameDescription
Protected methodWidgetHandlerTControl, TWidget, TCallback
Initializes a new instance of the WidgetHandlerTControl, TWidget, TCallback class
Top
Properties
  NameDescription
Public propertyCallback
Gets the callback object for the control
Top
Remarks
This can be used by controls that have events to trigger using a callback class.
Examples
This is a full example showing a new control with a handler-triggered event and a property.
// in your eto-only dll:
public class MyEtoControl : Eto.Forms.Control
{

    // define an event that is triggered by the handler
    public const string MySomethingEvent = "MyEtoControl.MySomething";

    public event EventHandler<EventArgs> MySomething
    {
        add { Properties.AddHandlerEvent(MySomethingEvent, value); }
        remove { Properties.RemoveEvent(MySomethingEvent, value); }
    }

    // allow subclasses to override the event
    protected virtual void OnMySomething(EventArgs e)
    {
        Properties.TriggerEvent(MySomethingEvent, this, e);
    }

    static MyEtoControl()
    {
        RegisterEvent<MyEtoControl>(c => c.OnMySomething(null), MySomethingEvent);
    }

    // defines the callback interface to trigger the event from handlers
    public interface ICallback : Eto.Control.ICallback
    {
        void OnMySomething(MyEtoControl widget, EventArgs e);
    }

    // defines the callback implementation
    protected class Callback : Eto.Control.Callback, ICallback
    {
        public void OnMySomething(MyEtoControl widget, EventArgs e)
        {
            using (widget.Platform.Context)
                widget.OnMySomething(e);
        }
    }

    // create single instance of the callback, and tell Eto we want to use it
    static readonly object callback = new Callback();
    protected override object GetCallback() { return callback; }

    // handler interface for other methods/properties
    public interface IHandler : Eto.Control.IHandler
    {
        string MyProperty { get; set; }
    }

    new IHandler Handler { get { (IHandler)base.Handler; } }

    public string MyProperty { get { return Handler.MyProperty; } set { Handler.MyProperty = value; } }
}


// in each platform-specific dll:
public class MyHandler : WidgetHandler<PlatformSpecificControl, MyEtoControl, MyEtoControl.ICallback> : MyEtoControl.IHandler
{
    public MyHandler()
    {
        Control = new PlatformSpecificControl();
    }

    public string MyProperty { get; set; }

    public override void AttachEvent(string id)
    {
        switch (id)
        {
            case MyEtoControl.MySomethingEvent:
                Control.SomeEvent += (sender, e) => Callback.OnMySomething(EventArgs.Empty);
                break;

            default:
                base.AttachEvent(id);
                break;
        }
    }
}
See Also

Reference