Widget
References- EnumDropDown<T>
- Dialog<T>
- GridView<T>
Nothing matches.
[RuntimeNameProperty("ID")]
public abstract class Widget : IHandlerSource, IDisposable, ICallbackSource
Base widget class for all objects requiring a platform-specific implementation
Remarks: The Widget is the base of all abstracted objects that have platform-specific implementations. To implement the handler for a widget, use the WidgetHandler<TWidget> as the base class.
Constructors
Widget
#protected Widget(IHandler handler)
Initializes a new instance of the Widget class
Parameters:
| handler (Widget.IHandler) | Handler to assign to this widget for its implementation |
Properties
ControlObject
#Gets the instance of the platform-specific object
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.
IsDisposed
#Gets or sets a value indicating whether this Widget has been disposed.
Remarks: When the widget is disposed, it can no longer be used.
Value:
true if this instance has been disposed; otherwise, false.NativeHandle
#public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
Platform
#Gets the platform that was used to create the Handler for this widget
Remarks: This gets set to the current Platform.Instance during the construction of the object
Style
#Gets or sets the style of this widget
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
Example:
// in your UI
var control = new Button { Style = "mystyle" };
// in your platform assembly
using Eto.Mac.Forms.Controls;
Styles.AddHandler<ButtonHandler>("mystyle", handler => {
// this is where you can use handler.Control to set properties, handle events, etc.
handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});Methods
Dispose
#Handles the disposal of this widget
GetCallback
#Gets an instance of an object used to perform callbacks to the widget from handler implementations
Remarks: The callback should implement the parent class' Widget.ICallback interface so that there only needs to be a single callback for the entire hierarchy. This should return a static instance to avoid having overhead for each instance of your control.
Returns: The callback instance to use for this widget
Initialize
#protected void Initialize()
Initializes the widget handler
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.
RegisterEvent<T>
#Registers the event for overridding
Remarks: This is used to register an event that will be automatically hooked up when a derived class overrides the event method. This should be called in the static constructor of your class.
Parameters:
| method (Expression<Action<T>>) | Expression to call the method that raises your event |
| identifier (string) | Identifier of the event |
Example:Shows a custom control with an event:
public class MyEtoControl : Eto.Forms.Control
{
public const string MySomethingEvent = "MyEtoControl.MySomethingEvent";
public event EventHandler<EventArgs> MySomething
{
add { Properties.AddHandlerEvent(MySomethingEvent, value); }
remove { Properties.RemoveEvent(MySomethingEvent, value); }
}
protected virtual void OnMySomething(EventArgs e)
{
Properties.TriggerEvent(MySomethingEvent, this, e);
}
static MyEtoControl()
{
RegisterEvent<MyEtoControl>(c => c.OnMySomething(null), MySomethingEvent);
}
}ToString
#Gets a string that represents the current object with its ID if specified.
Returns: A string value indicating the type and ID (if specified) of this widget.
Overrides: Object.ToString