# WidgetHandler<TControl, TWidget, TCallback> class

Namespace: [Eto](https://eto.picoe.ca/api/namespace/eto.md) · Assembly: [Eto](https://eto.picoe.ca/api/assembly/eto.md)

```cs
public abstract class WidgetHandler<TControl, TWidget, TCallback> : WidgetHandler<TControl, TWidget>
```

Widget handler with type-specific callback

**Remarks:** This can be used by controls that have events to trigger using a callback class.

**Type parameters:**

- `TControl`: Type of the platform-specific object
- `TWidget` (where Widget): Type of widget the handler is for
- `TCallback`: Type of the callback

**Example:**

This is a full example showing a new control with a handler-triggered event and a property.

```cs
// 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;
		}
	}
}
```

**Derived types:** [ThemedAboutDialogHandler](https://eto.picoe.ca/api/type/eto.forms.themedcontrols.themedaboutdialoghandler.md), [ThemedColorDialogHandler](https://eto.picoe.ca/api/type/eto.forms.themedcontrols.themedcolordialoghandler.md), [ThemedControlHandler<TControl, TWidget, TCallback>](https://eto.picoe.ca/api/type/eto.forms.themedcontrolhandler-3.md), [ThemedFontDialogHandler](https://eto.picoe.ca/api/type/eto.forms.themedcontrols.themedfontdialoghandler.md), [ThemedSegmentedItemHandler<TWidget, TCallback>](https://eto.picoe.ca/api/type/eto.forms.themedcontrols.themedsegmenteditemhandler-2.md)

## Properties

- [Callback](https://eto.picoe.ca/api/type/eto.widgethandler-3/callback.md): Gets the callback object for the control

## Inherited Members

- From [WidgetHandler<TControl, TWidget>](https://eto.picoe.ca/api/type/eto.widgethandler-2.md): [Connector](https://eto.picoe.ca/api/type/eto.widgethandler-2/connector.md), [Control](https://eto.picoe.ca/api/type/eto.widgethandler-2/control.md), [DisposeControl](https://eto.picoe.ca/api/type/eto.widgethandler-2/disposecontrol.md), [HasControl](https://eto.picoe.ca/api/type/eto.widgethandler-2/hascontrol.md), [CreateConnector](https://eto.picoe.ca/api/type/eto.widgethandler-2/createconnector.md), [CreateControl](https://eto.picoe.ca/api/type/eto.widgethandler-2/createcontrol.md), [Dispose](https://eto.picoe.ca/api/type/eto.widgethandler-2/dispose.md)
- From [WidgetHandler<TWidget>](https://eto.picoe.ca/api/type/eto.widgethandler-1.md): [ID](https://eto.picoe.ca/api/type/eto.widgethandler-1/id.md), [NativeHandle](https://eto.picoe.ca/api/type/eto.widgethandler-1/nativehandle.md), [Widget](https://eto.picoe.ca/api/type/eto.widgethandler-1/widget.md), [AttachEvent](https://eto.picoe.ca/api/type/eto.widgethandler-1/attachevent.md), [DetachEvent](https://eto.picoe.ca/api/type/eto.widgethandler-1/detachevent.md), [Dispose](https://eto.picoe.ca/api/type/eto.widgethandler-1/dispose.md), [HandleEvent](https://eto.picoe.ca/api/type/eto.widgethandler-1/handleevent.md), [Initialize](https://eto.picoe.ca/api/type/eto.widgethandler-1/initialize.md), [IsEventHandled](https://eto.picoe.ca/api/type/eto.widgethandler-1/iseventhandled.md), [OnInitializeComplete](https://eto.picoe.ca/api/type/eto.widgethandler-1/oninitializecomplete.md), [UnhandleEvent](https://eto.picoe.ca/api/type/eto.widgethandler-1/unhandleevent.md)
