UIElement Class
Represents a base object that has a user interface and implements IUIElement.
public class UIElement : LogicalTreeNodeBase, IInputElement, IUIElement, ILogicalTreeNode, IDpiAwareElement, IDisposable
- Inheritance:
- object MarshalByRefObject MarshalByRefDisposableObject LogicalTreeNodeBase object
- Derived:
- BarCommandLink DockableToolBar DockableToolBarRow StatusBarPanel AutoHideTab AutoHideTabGroup DockContainerTitleBarButton TabStripButton TabStripTab MarkupLabelUIElement NavigationBarOverflowMenuButton NavigationPaneButton CanvasControl ScrollBarButton ScrollBarThumb CollapsedRegionAdornment EditorViewHost EditorViewMarginBase EditorViewSelectionGripper EditorViewSplitter PrinterViewMarginBase ScrollBarBlock ScrollBarSplitter TextView UIElementComponent WizardButtonContainer WizardInteriorPageHeader
Constructors
UIElement()
Initializes an instance of the class.
public UIElement()
Properties
ActualHeight
The actual height of the element.
[Browsable(false)]
public int ActualHeight { get; }
Property Value
Remarks
This is determined by the layout system after Arrange(Rectangle) has completed.
This is only valid if IsArrangeValid is true.
ActualWidth
The actual width of the element.
[Browsable(false)]
public int ActualWidth { get; }
Property Value
Remarks
This is determined by the layout system after Arrange(Rectangle) has completed.
This is only valid if IsArrangeValid is true.
Bounds
A Rectangle specifying the bounds of the element.
CaptureMouseWhenPressed
Indicates whether to automatically capture the mouse when the element is pressed.
protected virtual bool CaptureMouseWhenPressed { get; }
Property Value
- bool:
trueif the mouse should automatically be captured when the element is pressed; otherwise,false.
ClipBounds
A Rectangle specifying the clip bounds when drawing the element.
DesiredSize
The desired size of the element as computed by Measure(Graphics?, Size).
[Browsable(false)]
public Size DesiredSize { get; }
Property Value
Remarks
This is only valid if IsMeasureValid is true.
DpiScaleFactor
The current DPI-based scale factor to be applied when rendering the element, where Width is applied to the x-axis, and Height is applied to the y-axis.
[Browsable(false)]
public SizeF DpiScaleFactor { get; }
Property Value
See Also
InvalidateOnMouseEvents
Indicates whether to invalidate the element when mouse events occur.
protected virtual bool InvalidateOnMouseEvents { get; }
Property Value
- bool:
trueif the element should be invalidated when mouse events occur; otherwise,false.
IsArrangeValid
Indicates whether the value of the DesiredSize property and position of child elements is valid.
[Browsable(false)]
public bool IsArrangeValid { get; }
Property Value
- bool:
trueif the value of the DesiredSize property and position of child elements is valid; otherwise,false.
Remarks
A developer can force arrangement to be invalidated by calling InvalidateArrange(). IsArrangeValid and IsMeasureValid are related, in that arrangement cannot be valid without measurement first being valid.
IsMeasureValid
Indicates whether the value of the DesiredSize property is valid.
[Browsable(false)]
public bool IsMeasureValid { get; }
Property Value
- bool:
trueif the value of the DesiredSize property is valid; otherwise,false.
Remarks
A developer can force arrangement to be invalidated by calling InvalidateMeasure(). IsArrangeValid and IsMeasureValid are related, in that arrangement cannot be valid without measurement first being valid.
IsMouseCaptured
Indicates whether the element is currently capturing the mouse.
[Browsable(false)]
public bool IsMouseCaptured { get; }
Property Value
- bool:
trueif the element is currently capturing the mouse; otherwise,false.
IsMouseDirectlyOver
Indicates whether the mouse is directly over the element.
protected bool IsMouseDirectlyOver { get; }
Property Value
- bool:
trueif the mouse is directly over the element; otherwise,false.
IsRightToLeft
Indicates whether the element is using a right-to-left layout.
[Browsable(false)]
public bool IsRightToLeft { get; }
Property Value
- bool:
trueif the element is using a right-to-left layout; otherwise,false.
Size
The actual size of the element.
[Browsable(false)]
public Size Size { get; }
Property Value
Remarks
This is determined by the layout system after Arrange(Rectangle) has completed.
This is only valid if IsArrangeValid is true.
VisualOffset
The X/Y offset of the element relative to its parent element's coordinate system.
[Browsable(false)]
public Point VisualOffset { get; }
Property Value
Remarks
This is determined by the layout system after Arrange(Rectangle) has completed.
This is only valid if IsArrangeValid is true.
Methods
AddPendingGraphicsInversion(Rectangle)
Inverts the canvas using XOR at the end of the current or next drawing operation.
protected bool AddPendingGraphicsInversion(Rectangle bounds)
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle | The bounds to invert. |
Returns
- bool:
trueif the inversion operation was added successfully; otherwise,false.
AddPendingScrollOperation(Rectangle, int, int)
Scrolls the canvas the specified amount at the beginning of the next drawing operation.
protected bool AddPendingScrollOperation(Rectangle bounds, int xAmount, int yAmount)
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle | The bounds to scroll. |
| xAmount | int | The amount to scroll horizontally. |
| yAmount | int | The amount to scroll vertically. |
Returns
- bool:
trueif the scroll operation was added successfully; otherwise,false.
AddPendingScrollOperation(Rectangle, Orientation, int)
Scrolls the canvas the specified amount at the beginning of the next drawing operation.
protected bool AddPendingScrollOperation(Rectangle bounds, Orientation orientation, int amount)
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle | The bounds to scroll. |
| orientation | Orientation | The direction to scroll. |
| amount | int | The amount to scroll. |
Returns
- bool:
trueif the scroll operation was added successfully; otherwise,false.
Arrange(Rectangle)
Positions child elements and determines a size for the IUIElement.
public void Arrange(Rectangle finalRect)
| Parameter | Type | Description |
|---|---|---|
| finalRect | Rectangle |
ArrangeOverride(Size)
Positions child elements and determines an arrange size.
protected virtual Size ArrangeOverride(Size finalSize)
| Parameter | Type | Description |
|---|---|---|
| finalSize | Size | The final area within the parent that this element should use to arrange itself and its children. |
Returns
- Size:
The actual size used.
Remarks
Element authors should override this method, call Arrange(Rectangle) on each visible child element and position each child element. It is required that a parent element calls Arrange(Rectangle) on each child or they won't be rendered.
CaptureMouse()
Attaches the mouse capture to the element.
public void CaptureMouse()
ContainsLocation(Point)
Used with hit-testing, returning whether this element's bounds contains the specified location.
public virtual bool ContainsLocation(Point location)
| Parameter | Type | Description |
|---|---|---|
| location | Point | The Point location to examine. |
Returns
- bool:
trueif this element's bounds contains the specified location; otherwise,false.
Remarks
Override this method to prevent certain portions of the element's bounds from being included in hit-testing.
CreateGraphics()
Creates the Graphics object for the use with the object.
Dispose(bool)
Releases the unmanaged resources used by the object and optionally releases the managed resources.
protected override void Dispose(bool disposing)
| Parameter | Type | Description |
|---|---|---|
| disposing | bool |
|
Remarks
This method is called by the public Dispose method and the Finalize method.
Dispose invokes this method with the disposing parameter set to true.
Finalize invokes this method with disposing set to false.
DpiScaleChanged(SizeF)
Called when the DPI-based scale factor of the element changes.
public virtual void DpiScaleChanged(SizeF scaleFactor)
| Parameter | Type | Description |
|---|---|---|
| scaleFactor | SizeF | The new scale factor where Width is applied to the x-axis, and Height is applied to the y-axis. |
See Also
GetCursor(Point)
public virtual Cursor? GetCursor(Point point)
| Parameter | Type | Description |
|---|---|---|
| point | Point | The Point to examine. |
Returns
GetDrawState()
The UIElementDrawState for the element.
public virtual UIElementDrawState GetDrawState()
Returns
Remarks
The default implementation of this method returns None.
Invalidate()
Invalidates the area of the object and causes it to be repainted.
public void Invalidate()
Invalidate(InvalidationLevels, InvalidationTypes)
Invalidates the specified states for the element or its related elements.
public void Invalidate(InvalidationLevels levels, InvalidationTypes types)
| Parameter | Type | Description |
|---|---|---|
| levels | InvalidationLevels | The hierarchy levels at which to invalidate. |
| types | InvalidationTypes | The types of invalidation to perform. |
Invalidate(Rectangle)
Invalidates an area in the object and causes it to be repainted.
public void Invalidate(Rectangle rect)
| Parameter | Type | Description |
|---|---|---|
| rect | Rectangle | The bounds of the rectangle to invalidate. |
InvalidateArrange()
Invalidates the layout of the element.
public void InvalidateArrange()
InvalidateMeasure()
Invalidates the measurement of the element.
public void InvalidateMeasure()
Measure(Graphics?, Size)
Measures the element and updates the DesiredSize property.
public void Measure(Graphics? g, Size availableSize)
| Parameter | Type | Description |
|---|---|---|
| g | Graphics | The Graphics object to use for measurement. |
| availableSize | Size | The available size that parent can give to the child. The child can return bigger in hopes that the parent will become scrollable. The value may also be infinity to indicate that the desired measurements of the element are wanted. |
Remarks
The Measure(Graphics?, Size) method should be called by parents on their children.
Internally, Measure(Graphics?, Size) calls the MeasureCore override on the same object, giving it opportunity to compute its DesiredSize.
This method will return immediately if the child's measurements are valid, previously measured and availableSize is the same as cached.
This method also resets the IsMeasureValid bit on the child.
MeasureOverride(Graphics?, Size)
Measures the size in layout required for child elements and determines a size for the element itself.
protected virtual Size MeasureOverride(Graphics? g, Size availableSize)
| Parameter | Type | Description |
|---|---|---|
| g | Graphics | The Graphics object to use for measurement. |
| availableSize | Size | The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available. |
Returns
- Size:
The size that this element determines it needs during layout, based on its calculations of child element sizes.
Remarks
Element authors should override this method, call Measure(Graphics?, Size) on each visible child element and determine the total size required.
OnClick(MouseEventArgs)
Raises the Click event.
protected virtual void OnClick(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnDoubleClick(MouseEventArgs)
Raises the DoubleClick event.
protected virtual void OnDoubleClick(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseCaptureLost(EventArgs)
Raises the MouseCaptureLost event.
protected virtual void OnMouseCaptureLost(EventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
OnMouseDown(MouseEventArgs)
Raises the MouseDown event.
protected virtual void OnMouseDown(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseEnter(MouseEventArgs)
Raises the MouseEnter event.
protected virtual void OnMouseEnter(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseHover(MouseEventArgs)
Raises the MouseHover event.
protected virtual void OnMouseHover(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseLeave(MouseEventArgs)
Raises the MouseLeave event.
protected virtual void OnMouseLeave(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseMove(MouseEventArgs)
Raises the MouseMove event.
protected virtual void OnMouseMove(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseUp(MouseEventArgs)
Raises the MouseUp event.
protected virtual void OnMouseUp(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnMouseWheel(MouseEventArgs)
Raises the MouseWheel event.
protected virtual void OnMouseWheel(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The event data. |
OnParentChanged()
Invoked when logical parent is changed. This is invoked after the parent has changed, and the purpose is to allow elements to perform actions based on the changed parent.
protected override void OnParentChanged()
OnRender(PaintEventArgs)
Renders the element.
protected virtual void OnRender(PaintEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | PaintEventArgs | The event data. |
OnRenderChildElements(PaintEventArgs)
Renders the child elements.
protected virtual void OnRenderChildElements(PaintEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | PaintEventArgs | The event data. |
Remarks
This method should not generally be overridden. The default implementation of this method calls the Render(PaintEventArgs) method on all child elements.
OnResize(EventArgs)
Raises the Resize event.
protected virtual void OnResize(EventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | The event data. |
PostArrangeOverride()
Allows custom logic to be executed following a successful call to the ArrangeOverride(Size) method.
protected virtual void PostArrangeOverride()
ReleaseMouseCapture()
Releases the mouse capture, if any.
public void ReleaseMouseCapture()
Render(PaintEventArgs)
Renders the element.
public void Render(PaintEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | PaintEventArgs | The event data. |
TransformToAncestor(IUIElement)
Returns a GeneralTransform from this element to an ancestor element.
public GeneralTransform TransformToAncestor(IUIElement ancestor)
| Parameter | Type | Description |
|---|---|---|
| ancestor | IUIElement | The ancestor IUIElement. |
Returns
TransformToDescendant(IUIElement)
Returns a GeneralTransform from this element to a descendant element.
public GeneralTransform TransformToDescendant(IUIElement descendant)
| Parameter | Type | Description |
|---|---|---|
| descendant | IUIElement | The descendant IUIElement. |
Returns
UpdateLayout()
Call this method to ensure that the whole subtree of elements that includes this UIElement is properly updated.
public virtual void UpdateLayout()
Remarks
This ensures that UIElement objects with invalid measure or arrange states will get a call to their Measure(Graphics?, Size) and Arrange(Rectangle) methods, and all computed sizes will be validated. This method does nothing if layout is clean but it does work if layout is not clean so avoid calling it after each change in the element tree. It makes sense to either never call it (system will do this in a deferred manner) or only call it if you absolutely need updated sizes and positions after you do all changes.
Events
Click
Occurs when the object is clicked.
DoubleClick
Occurs when the object is double-clicked.
MouseCaptureLost
Occurs when the mouse loses capture.
MouseDown
Occurs when the mouse pointer is over the object and a mouse button is pressed.
MouseEnter
Occurs when the mouse pointer enters the object.
MouseHover
Occurs when the mouse pointer hovers over the object.
MouseLeave
Occurs when the mouse pointer leaves the object.
MouseMove
Occurs when the mouse pointer is moved over the object.
MouseUp
Occurs when the mouse pointer is over the object and a mouse button is released.
MouseWheel
Occurs when the mouse wheel moves while the object has focus.
Resize
Occurs when the object is resized.
Inherited Members
- LogicalTreeNodeBase.CreateChildren()
- MarshalByRefDisposableObject.Dispose()
- MarshalByRefDisposableObject.VerifyNotDisposed()
- MarshalByRefDisposableObject.IsDisposed
- MarshalByRefDisposableObject.Disposed
- MarshalByRefObject.GetLifetimeService()
- MarshalByRefObject.InitializeLifetimeService()
- MarshalByRefObject.MemberwiseClone(bool)
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()
Extension Methods
- DpiAwareElementExtensions.AutoScaleFont(IDpiAwareElement, Font)
- DpiAwareElementExtensions.AutoScaleFontSize(IDpiAwareElement, float)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, Padding)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, Point)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, Rectangle)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, Size)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, SizeF)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, int)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, float)
- DpiAwareElementExtensions.ScaleLogicalValue(IDpiAwareElement, Padding)
- DpiAwareElementExtensions.SynchronizeScaleFactorWithChildren(IDpiAwareElement)
- ILogicalTreeNodeExtensions.FindCommonLogicalAncestor(ILogicalTreeNode, ILogicalTreeNode)
- ILogicalTreeNodeExtensions.FindLogicalAncestorOfType<T>(ILogicalTreeNode, bool)
- ILogicalTreeNodeExtensions.FindLogicalDescendantOfType<T>(ILogicalTreeNode, bool)
- ILogicalTreeNodeExtensions.GetLogicalAncestors(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetLogicalChildren(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetLogicalDescendants(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetLogicalParent(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetLogicalParent<T>(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetLogicalSiblings(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetSelfAndLogicalAncestors(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.GetSelfAndLogicalDescendants(ILogicalTreeNode)
- ILogicalTreeNodeExtensions.IsLogicalAncestorOf(ILogicalTreeNode, ILogicalTreeNode)
- ObjectExtensions.TryConvertToDouble(object, out double)
- ObjectExtensions.TryConvertToDouble(object, IFormatProvider, out double)