- EnumDropDown<T>
- Dialog<T>
- GridView<T>
Nothing matches.
[TypeConverter(ControlConverter)]
public class Control : BindableWidget, IMouseInputSource, IKeyboardInputSource, ICallbackSource
Base for all visual UI elements
Remarks: All visual user interface elements should inherit from this class to provide common functionality like binding, load/unload, and common events.
Constructors
Control
#public Control(IHandler handler)
Initializes a new instance of the Container with the specified handler
Parameters:
| handler (Control.IHandler) | Pre-created handler to attach to this instance |
Fields
Event identifier for handlers when attaching the ThemeChanged event
Properties
BackgroundColor
#Gets or sets the color for the background of the control
Remarks: Note that on some platforms (e.g. Mac), setting the background color of a control can change the performance characteristics of the control and its children, since it must enable layers to do so.
Value: The color of the background.
Bindings
Gets the collection of bindings that are attached to this widget
Bounds
#Gets the bounding rectangle of this control relative to its container
Value: The bounding rectangle of the control
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 Widget.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.
DataContext
Gets or sets the data context for this widget for binding
Remarks: Subclasses may override the standard behaviour so that hierarchy of widgets can be taken into account. For example, a Control may return the data context of a parent, if it is not set explicitly.
Implements: DataContext
Enabled
#Gets or sets a value indicating whether this Control (or its children) are enabled and accept user input.
Remarks: Typically when a control is disabled, the user cannot do anything with the control or any of its children. Including for example, selecting text in a text control. Certain controls can have a 'Read Only' mode, such as TextBox.ReadOnly which allow the user to select text, but not change its contents.
Value:
true if enabled; otherwise, false.Gets the gestures attached to this control.
Handler
#Gets the handler for the widget, ensuring the current thread is the UI thread
Value: The handler object for this control
HasFocus
#Gets a value indicating whether this instance has the keyboard input focus.
Value:
true if this instance has focus; otherwise, false.IsDataContextChanging
Gets a value indicating that the BindableWidget.DataContext property is changing.
Remarks: This can be used to determine when to allow certain logic during the update of the data context. It is used to disable binding setters on the model when the data context changes so that a binding does not cause the view model to be updated when the state hasn't been fully set yet.
Value:
true if the DataContext is currently changing, false otherwise.Implements: IsDataContextChanging
Gets or sets a value indicating the UI is being shown in a designer preview, e.g. to supply sample data.
Remarks: Set by the designer when it starts; applications should not need to set this.
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.IsMouseCaptured
#Gets a value indicating this control currently has mouse capture
Remarks: Mouse capture can happen during a handled MouseDown event until MouseUp, or it can be captured explicitly via CaptureMouse().
IsSuspended
#Gets a value indicating whether the layout of child controls is suspended.
Value:
true if this instance is suspended; otherwise, false.IsVisualControl
#Gets a value indicating this Control is part of the visual tree.
Value:
true if is visual control; otherwise, false.Loaded
#Gets a value indicating that the control is loaded onto a form, that is it has been created, added to a parent, and shown
Remarks: The OnLoad(EventArgs) method sets this value to
true after cascading to all children (for a Container) and calling the platform handler's implementation. It is called after adding to a loaded form, or when showing a new form. The OnUnLoad(EventArgs) method will set this value to false when the control is removed from its parentLocation
#Gets the location of the control as positioned by the container
Remarks: A control's location is set by the container. This can be used to determine where the control is for overlaying floating windows, menus, etc.
Value: The current location of the control
LogicalParent
#Gets the logical parent control.
Remarks: When the control is part of the visual tree (IsVisualControl is true), this returns the logical parent that contains this control. Otherwise this is the same as Parent.
Value: The logical parent.
NativeHandle
public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
Parent
#Gets the container which this control has been added to, if any
Value: The parent control, or null if there is no parent
Parents
Gets an enumeration of all parent widgets in the heirarchy by traversing the BindableWidget.Parent property.
ParentWindow
#Gets the window this control is contained in
Value: The parent window, or null if it is not currently on a window
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object
Size
#Gets or sets the size of the control. Use -1 to specify auto sizing for either the width and/or height.
Remarks: Setting the size of controls is entirely optional as most controls will size themselves appropriately. When specifying a size, it will be used as the desired size of the control. The container will reposition and resize the control depending on the available size. For a Window, it is preferred to set the Container.ClientSize instead, as various platforms have different sizes of window decorations, toolbars, etc.
Value: The current size of the control
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;
});SupportedPlatformCommands
#Gets the supported platform commands that can be used to hook up system functions to user defined logic
Remarks: This lists all available commands that can be mapped using the MapPlatformCommand(string, Command) method of the control.
Value: The supported platform commands.
See Also: MapPlatformCommand(string, Command)
TabIndex
#Gets or sets the tab index order for this control within its container.
Remarks: This sets the order when using the tab key to cycle through controls Note that some platforms (Gtk and WinForms) may not support setting the context of the tab order to StackLayout or DynamicLayout containers and may not behave exactly as expected. Use the PlatformFeatures.TabIndexWithCustomContainers flag to determine if it is supported.
Value: The index of the control in the tab order.
Gets or sets a value indicating whether the user can get to this control using the tab key.
Remarks: When
false, the control is skipped when cycling through controls with the tab key, but can still be focused by clicking on it or by calling Focus(). This is useful for composite controls where only part of the control should be in the tab order, such as the spinner of a TextStepper or NumericStepper. The tab key only cycles through the controls within a window, so this has no effect for a Window. Note that on Gtk this maps directly to whether the underlying widget can be focused, so it also prevents the control from being focused by clicking on it, and controls that never accept focus (such as a Label) will report false. On iOS and Android this has no effect.Value:
true to include the control in the tab order (the default); false to skip it.Tag
#Gets or sets a user-defined object that contains data about the control
Remarks: A common use of the tag property is to store data that is associated with the control that you can later retrieve.
Visible
#Gets or sets a value indicating whether this Control is visible to the user.
Remarks: When the visibility of a control is set to false, it will not occupy space in the layout.
Value:
true if visible; otherwise, false.VisualControls
#Gets an enumeration of controls that are in the visual tree.
Remarks: This is used to specify which controls are contained by this instance that are part of the visual tree. This should include all controls including non-logical Eto controls used for layout.
Value: The visual controls.
VisualParent
#Gets the visual container of this control, if any.
Remarks: Some containers may use other Eto controls to layout its children, such as the StackLayout. This will return the parent control that visually contains this control as opposed to Parent which will return the logical parent.
Value: The visual parent of this control.
Methods
ApplyStyles
#Applies the styles to the specified
widget up the parent chain.Remarks: This traverses up the parent chain to apply any cascading styles defined in parent container objects. Call this method on any child widget of a control.
AttachNative
#public void AttachNative()
Attaches the control for direct use in a native application
Remarks: Use this to use a control directly in a native application. Note that the native application must be running the same framework as the current platform. E.g. a WinForms application can use an Eto.Forms control when using the Eto.WinForms platform. This prepares the control by firing the PreLoad, Load, etc. events.
CaptureMouse
#Captures all mouse events to this control.
Remarks: This captures all mouse events until ReleaseMouseCapture() is called. Note that not all platforms will allow a mouse capture unless the mouse is currently down.
Returns:
true if the mouse was captured, false otherwise.Detach
#public void Detach()
Detaches the control by removing it from its parent
Remarks: This is essentially a shortcut to myControl.Parent.Remove(myControl);
DetachNative
#public void DetachNative()
Detaches the control when it is used in a native application, when you want to reuse the control.
Remarks: This should only be called after AttachNative() has been called, which is usually done by calling to
ToNative(true).Dispose
public void Dispose()
Disposes of this widget, supressing the finalizer
Dispose
#Handles the disposal of this control
Parameters:
| disposing (bool) | True if the caller called Widget.Dispose() manually, false if being called from a finalizer |
Overrides: Widget.Dispose
DoDragDrop
#public virtual void DoDragDrop(DataObject data, DragEffects allowedEffects, Image image, PointF cursorOffset)
Starts drag operation using this control as drag source.
Remarks: This method can be blocking on some platforms (Wpf, WinForms), and non-blocking on others (Mac, Gtk). Use the DragEnd event to determine when the drag operation is completed and get its resulting DragEffects.
Parameters:
| data (DataObject) | Drag data. |
| allowedEffects (DragEffects) | Allowed effects. |
| image (Image) | Custom drag image |
| cursorOffset (PointF) | Offset of the cursor to the drag image |
DoDragDrop
#Starts drag operation using this control as drag source.
Remarks: This method can be blocking on some platforms (Wpf, WinForms), and non-blocking on others (Mac, Gtk). Use the DragEnd event to determine when the drag operation is completed and get its resulting DragEffects.
Parameters:
| data (DataObject) | Drag data. |
| allowedEffects (DragEffects) | Allowed action. |
FindParent
#Finds a control in the parent hierarchy with the specified
idParameters:
| id (string) | Identifier of the parent control to find. |
Returns: The parent if found, or null if not found.
FindParent
#Finds a control in the parent hierarchy with the specified type and Widget.ID if specified
Focus
#public virtual void Focus()
Attempts to set the keyboard input focus to this control, or the first child that accepts focus. For Windows, this will bring it to front and activate it.
GetCallback
#Gets an instance of an object used to perform callbacks to the widget from handler implementations.
Returns: The callback instance to use for this widget
Overrides: Widget.GetCallback
GetPreferredSize
#Gets the preferred size of this control given infinite space available.
Returns: The size this control would prefer to be
GetPreferredSize
#Gets the preferred size of this control given the specified
availableSize.Parameters:
| availableSize (SizeF) | The available size to determine the preferred size |
Returns: The preferred size this control would like to be, which can be larger than the specified
availableSize.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.
Invalidate
#public void Invalidate()
Queues a repaint of the entire control on the screen and any of its children.
Remarks: This is only useful when the control is visible.
Invalidate
#Queues a repaint of the entire control on the screen
Remarks: This is only useful when the control is visible.
Parameters:
| invalidateChildren (bool) | True to invalidate all children, false to only invalidate the container |
Invalidate
#Queues a repaint of the specified
rect of the controlInvalidate
#Queues a repaint of the specified
rect of the control and any children.Remarks: This is only useful when the control is visible.
Parameters:
| rect (Rectangle) | Rectangle to repaint |
MapPlatformCommand
#Specifies a command to execute for a platform-specific command
Remarks: Some platforms have specific system-defined commands that can be associated with a control. For example, the Mac platform's cut/copy/paste functionality is defined by the system, and if you want to hook into it, you can use this to map it to your own defined logic. The valid values of the
systemCommand parameter are defined by each platform, and a list can be retrieved using SupportedPlatformCommandsParameters:
| systemCommand (string) | System command |
| command (Command) | Command to execute, or null to restore to the default behavior |
See Also: SupportedPlatformCommands
Example:This example shows how to extend a control with cut/copy/paste for the mac platform:
var drawable = new Drawable();
if (drawable.Generator.IsMac)
{
drawable.MapPlatformCommand("cut", new MyCutCommand());
drawable.MapPlatformCommand("copy", new MyCopyCommand());
drawable.MapPlatformCommand("paste", new MyPasteCommand());
}OnApplyCascadingStyles
#protected virtual void OnApplyCascadingStyles()
Called when cascading styles should be applied to this control.
Remarks: You don't typically have to call this directly, but override it to apply styles to any child item(s) that may need styling at the same time. This is automatically done for any Container based control and its child controls.
inherited fromBindableWidget
Remarks: Implementors may override this to fire this event on child widgets in a heirarchy. Alternatively, implement IBindableWidgetContainer for your widget and this will trigger any events on the children automatically. This allows a control to be bound to its own BindableWidget.DataContext, which would be set on one of the parent control(s).
Parameters:
| e (EventArgs) | Event arguments |
OnMouseDoubleClick
#Raises the mouse MouseDoubleClick event.
Parameters:
| e (MouseEventArgs) | Mouse event arguments |
OnMouseDown
#Raises the MouseDown event.
Remarks: To override default behaviour of the control, set MouseEventArgs.Handled property to
true.Parameters:
| e (MouseEventArgs) | Event arguments |
OnMouseLeave
#Raises the MouseLeave event.
Parameters:
| e (MouseEventArgs) | Mouse event arguments |
See Also: MouseEnter
OnStyleChanged
#Handles when the Style is changed.
Remarks: This applies the cascading styles to the control and any of its children.
Parameters:
| e (EventArgs) |
Overrides: Widget.OnStyleChanged
Raises the ThemeChanged event.
PointFromScreen
#Converts a point from screen space to control space.
Parameters:
| point (PointF) | Point in screen space |
Returns: The point in control space
PointToScreen
#Converts a point from control space to screen space
Parameters:
| point (PointF) | Point in control space |
Returns: The point in screen space
RectangleFromScreen
#Converts a rectangle from screen space to control space.
Parameters:
| rect (RectangleF) | Rectangle in screen space |
Returns: The rectangle in control space
RectangleToScreen
#Converts a rectangle from control space to screen space
Parameters:
| rect (RectangleF) | Rectangle in control space |
Returns: The rectangle in screen space
ReleaseMouseCapture
#public void ReleaseMouseCapture()
Releases the mouse capture after a call to CaptureMouse().
ResumeLayout
#public virtual void ResumeLayout()
Resumes the layout after it has been suspended, and performs a layout
Remarks: This can be used to optimize some platforms while adding, removing, or changing many child controls at once. Each call to ResumeLayout() must be balanced with a call to SuspendLayout() before it.
SuspendLayout
#public virtual void SuspendLayout()
Suspends the layout of child controls
Remarks: This can be used to optimize some platforms while adding, removing, or changing many child controls at once. It disables the calculation of control positioning until ResumeLayout() is called. Each call to SuspendLayout() must be balanced with a call to ResumeLayout().
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
TriggerStyleChanged
#public void TriggerStyleChanged()
Triggers the StyleChanged event and re-applies the styles to this control and its children.
Unbind
public virtual void Unbind()
Unbinds any bindings in the BindableWidget.Bindings collection and removes the bindings
Remarks: When you implement IBindableWidgetContainer, this will also unbind any of its children.
UpdateBindings
Updates all bindings in this widget
Remarks: When you implement IBindableWidgetContainer, this will also update bindings for all of its children.
Parameters:
| mode (BindingUpdateMode = BindingUpdateMode.Source) |
UpdateLayout
#public void UpdateLayout()
Updates the layout of this control if necessary.
Remarks: This will ensure the control has had all of its layout applied so you can use its position and size right after this call. Most platforms (except WinForms) use a deferred layout system so that after adding your control to the form dynamically it won't get laid out until the next idle loop. This is useful when you need to know the dimensions of the control immediately. Note that this can be an expensive operation, so it is recommended to only call this method when necessary and after all of the controls have been added/updated.
Events
inherited fromBindableWidget
Remarks: This may be fired in the event of a parent in the hierarchy setting the data context. For example, the Container widget fires this event when it's event is fired.
Implements: DataContextChanged
DragDrop
#Occurs when a drag operation is dropped onto the control.
Remarks: This should perform any of the actual drop logic and update the control state to reflect the dropped data. Any cleanup should be performed in the DragLeave event, which is called immediately before this event.
DragEnd
#Occurs for a source control after a call to DoDragDrop(DataObject, DragEffects, Image, PointF) when the drag operation has ended. The DragEventArgs.Effects is the final DragEffects used at the drop destination.
Remarks: For controls that you are dragging from this event is useful to know what to do with the dragged content after it is dropped in a different control or application.
DragLeave
#Occurs when a drag operation leaves the bounds of the control or the drag operation was completed inside the control.
Remarks: Use this event to 'clean up' any state of the control for the current drag operation. This will be called before the DragDrop event.
DragOver
#Occurs when a drag operation is over the control and needs updating based on position or keyboard state changes.
GotFocus
#Occurs when the control receives keyboard focus.
Remarks: Note that not all controls can recieve keyboard focus.
See Also: LostFocus
Load
#Occurs when the control is displayed on a visible window
Remarks: A control is loaded when it is part of the control hierarchy and is shown on a window. When the control is removed from the hierarchy, or the window is closed, the UnLoad event will be called.
LoadComplete
#Occurs when the load is complete, which happens after the Load event and before the window/control is shown.
Remarks: This is a good place to reposition a Window before it is shown.
LostFocus
#Occurs when control loses keyboard focus
Remarks: Note that not all controls can recieve keyboard focus
See Also: GotFocus
MouseDoubleClick
#Occurs when a mouse button is double clicked within the bounds of the control
Remarks: If you do not set the MouseEventArgs.Handled property to true, and the default behaviour of the control does not accept double clicks, the MouseDown event will be called for each click of the mouse button. For example, if the user clicks twice in succession, the following will be called:
- MouseDown for the first click
- MouseDoubleClick for the second click
- If Handled has not been set in #2, MouseDown will be called a 2nd time
Implements: MouseDoubleClick
See Also: MouseDown
MouseDown
#Occurs when a mouse button has been pressed
MouseMove
#Occurs when mouse moves within the bounds of the control, or when the mouse is captured
Shown
#Occurs when the control is shown on the screen
Remarks: This event fires when the Visible property changes, or when initially showing a control on a form.
inherited fromWidget
Occurs when the control's theme changes either due to a system theme change or when Application.Instance.CurrentTheme is set.
UnLoad
#Occurs when the control is unloaded, which happens when removed from the control hierarchy or the window is closed.