WidgetHandlerTControl, TWidget, TCallback Class |
Namespace: Eto
public abstract class WidgetHandler<TControl, TWidget, TCallback> : WidgetHandler<TControl, TWidget> where TWidget : Widget
The WidgetHandlerTControl, TWidget, TCallback type exposes the following members.
Name | Description | |
---|---|---|
WidgetHandlerTControl, TWidget, TCallback | Initializes a new instance of the WidgetHandlerTControl, TWidget, TCallback class |
// 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; } } }