Class UIElement
- Namespace
- GHIElectronics.Endpoint.UI
- Assembly
- GHIElectronics.Endpoint.UI.dll
public abstract class UIElement : DispatcherObject
- Inheritance
-
UIElement
- Derived
- Inherited Members
Constructors
UIElement()
protected UIElement()
Fields
_horizontalAlignment
protected HorizontalAlignment _horizontalAlignment
Field Value
_verticalAlignment
protected VerticalAlignment _verticalAlignment
Field Value
Properties
ActualHeight
public int ActualHeight { get; }
Property Value
ActualWidth
public int ActualWidth { get; }
Property Value
Height
public int Height { get; set; }
Property Value
HorizontalAlignment
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
InstanceEventHandlersStore
Ensure the store has been created.
protected Hashtable InstanceEventHandlersStore { get; }
Property Value
IsArrangeValid
Determines if the RenderSize and position of child elements is valid.
public bool IsArrangeValid { get; }
Property Value
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.
IsEnabled
Fetches the value of the IsEnabled property
public bool IsEnabled { get; set; }
Property Value
IsFocused
A property indicating if the button is focused on this element or not.
public bool IsFocused { get; }
Property Value
IsMeasureValid
Determines if the DesiredSize is valid.
public bool IsMeasureValid { get; }
Property Value
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.
IsVisible
A property indicating if this element is Visible or not.
public bool IsVisible { get; }
Property Value
LogicalChildren
protected UIElementCollection LogicalChildren { get; }
Property Value
Parent
public UIElement Parent { get; }
Property Value
RootUIElement
public UIElement RootUIElement { get; }
Property Value
VerticalAlignment
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
Visibility
Visibility accessor
public Visibility Visibility { get; set; }
Property Value
Width
public int Width { get; set; }
Property Value
Methods
AddHandler(RoutedEvent, RoutedEventHandler, bool)
Adds a routed event handler for the particular RoutedEvent
public void AddHandler(RoutedEvent routedEvent, RoutedEventHandler handler, bool handledEventsToo)
Parameters
routedEventRoutedEventRoutedEvent for which the handler is attached
handlerRoutedEventHandlerThe handler that will be invoked on this object when the RoutedEvent is raised
handledEventsTooboolFlag indicating whether or not the listener wants to hear about events that have already been handled
Remarks
The handler added thus is also known as an instance handler
NOTE: It is not an error to add a handler twice (handler will simply be called twice)
Input parameters RoutedEvent and handler cannot be null
handledEventsToo input parameter when false means that listener does not care about already handled events. Hence the handler will not be invoked on the target if the RoutedEvent has already been Handled handledEventsToo input parameter when true means that the listener wants to hear about all events even if they have already been handled. Hence the handler will be invoked irrespective of the event being HandledAddToEventRoute(EventRoute, RoutedEventArgs)
Add the event handlers for this element to the route.
public void AddToEventRoute(EventRoute route, RoutedEventArgs args)
Parameters
routeEventRouteargsRoutedEventArgs
Arrange(int, int, int, int)
Parents or system call this method to arrange the internals of children on a second pass of layout update.
public void Arrange(int finalRectX, int finalRectY, int finalRectWidth, int finalRectHeight)
Parameters
finalRectXintThis is the final X location that parent or system wants this UIElement to assume.
finalRectYintThis is the final Y location that parent or system wants this UIElement to assume.
finalRectWidthintThis is the Width that parent or system wants this UIElement to assume.
finalRectHeightintThis is the height that parent or system wants this UIElement to assume.
Remarks
This method internally calls ArrangeOverride override, giving the derived class opportunity to arrange its children and/or content using final computed size. In their ArrangeOverride overrides, derived class is supposed to create its visual structure and prepare itself for rendering. Arrange is called by parents from their implementation of ArrangeOverride or by system when needed. This method sets Bounds=finalSize before calling ArrangeOverride.
ArrangeOverride(int, int)
ArrangeOverride allows for the customization of the final sizing and positioning of children.
protected virtual void ArrangeOverride(int arrangeWidth, int arrangeHeight)
Parameters
Remarks
UIElement authors should override this method, call Arrange on each visible child UIElement,
to size and position each child UIElement by passing a rectangle reserved for the child within parent space.
Note: It is required that a parent UIElement calls Arrange on each child or they won't be rendered.
Typical override follows a pattern roughly like this (pseudo-code):
protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight)
{
foreach (UIElement child in VisualChildren)
{
child.Arrange(new Rect(childX, childY, childWidth, childHeight);
}
}</code></pre>
ChildElementFromPoint(int, int)
public UIElement ChildElementFromPoint(int x, int y)
Parameters
Returns
ContainsPoint(int, int)
public bool ContainsPoint(int x, int y)
Parameters
Returns
GetDesiredSize(out int, out int)
public void GetDesiredSize(out int width, out int height)
Parameters
GetLayoutOffset(out int, out int)
public void GetLayoutOffset(out int x, out int y)
Parameters
GetMargin(out int, out int, out int, out int)
public void GetMargin(out int left, out int top, out int right, out int bottom)
Parameters
GetPointerTarget(int, int)
public UIElement GetPointerTarget(int x, int y)
Parameters
Returns
GetRenderSize(out int, out int)
public void GetRenderSize(out int width, out int height)
Parameters
GetUnclippedSize(out int, out int)
public void GetUnclippedSize(out int width, out int height)
Parameters
Invalidate()
public void Invalidate()
InvalidateArrange()
Invalidates the arrange state for the UIElement. The UIElement will be queued for an update layout that will occur asynchronously. MeasureOverride will not be called unless InvalidateMeasure is also called - or that something else caused the measure state to be invalidated.
public void InvalidateArrange()
InvalidateMeasure()
Invalidates the measurement state for the UIElement. This has the effect of also invalidating the arrange state for the UIElement. The UIElement will be queued for an update layout that will occur asynchronously.
public void InvalidateMeasure()
InvalidateRect(int, int, int, int)
public void InvalidateRect(int x, int y, int w, int h)
Parameters
Measure(int, int)
Updates DesiredSize of the UIElement. Must be called by parents from their MeasureOverride, to form recursive update. This is first pass of layout update.
public void Measure(int availableWidth, int availableHeight)
Parameters
availableWidthintAvailable width that parent can give to the child. May be MaxValue (when parent wants to measure to content). This is soft constraint. Child can return bigger size to indicate that it wants bigger space and hope that parent can throw in scrolling...
availableHeightintAvailable height that parent can give to the child. May be MaxValue (when parent wants to measure to content). This is soft constraint. Child can return bigger size to indicate that it wants bigger space and hope that parent can throw in scrolling...
Remarks
Measure is called by parents on their children. Internally, Measure calls MeasureOverride override on the same object, giving it opportunity to compute its DesiredSize.
This method will return immediately if child is not Dirty, previously measured and availableSize is the same as cached. This method also resets the IsMeasureinvalid bit on the child. In case when "unbounded measure to content" is needed, parent can use availableSize as double.PositiveInfinity. Any returned size is OK in this case.MeasureOverride(int, int, out int, out int)
Measurement override. Implement your size-to-content logic here.
protected virtual void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)
Parameters
availableWidthintAvailable size that parent can give to the child. May be MaxValue(when parent wants to measure to content). This is soft constraint. Child can return bigger size to indicate that it wants bigger space and hope that parent can throw in scrolling...
availableHeightintdesiredWidthintdesiredHeightint
Remarks
MeasureOverride is designed to be the main customizability point for size control of layout. UIElement authors should override this method, call Measure on each child UIElement, and compute their desired size based upon the measurement of the children. The return value should be the desired size.
Note: It is required that a parent UIElement calls Measure on each child or they won't be sized/arranged. Typical override follows a pattern roughly like this (pseudo-code):protected override void MeasureOverride(int avialableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)
{
foreach (UIElement child in VisualChildren)
{
child.Measure(availableSize);
availableSize.Deflate(child.DesiredSize);
_cache.StoreInfoAboutChild(child);
}
Size desired = CalculateBasedOnCache(_cache);
return desired;
}</code></pre>
- You must call Measure on each child UIElement
- It is common to cache measurement information between the MeasureOverride and ArrangeOverride method calls
- Calling base.MeasureOverride is not required.
- Calls to Measure on children are passing either the same availableSize as the parent, or a subset of the area depending on the type of layout the parent will perform (for example, it would be valid to remove the area for some border or padding).
OnButtonDown(ButtonEventArgs)
An event reporting a button was pressed.
protected virtual void OnButtonDown(ButtonEventArgs e)
Parameters
OnButtonUp(ButtonEventArgs)
An event reporting a button was released.
protected virtual void OnButtonUp(ButtonEventArgs e)
Parameters
OnChildDesiredSizeChanged(UIElement)
Notification that is called by Measure of a child when it ends up with different desired size for the child.
protected virtual void OnChildDesiredSizeChanged(UIElement child)
Parameters
childUIElement
Remarks
Default implementation simply calls invalidateMeasure(), assuming that layout of a parent should be updated after child changed its size.
Finer point: this method can only be called in the scenario when the system calls Measure on a child, not when parent calls it since if parent calls it, it means parent has dirty layout and is recalculating already.OnChildrenChanged(UIElement, UIElement, int)
OnChildrenChanged is called when the UIElementCollection of the UIElement is edited.
protected virtual void OnChildrenChanged(UIElement added, UIElement removed, int indexAffected)
Parameters
OnGenericEvent(GenericEventArgs)
protected virtual void OnGenericEvent(GenericEventArgs e)
Parameters
OnGotFocus(FocusChangedEventArgs)
An event announcing that the buttons are focused on this element.
protected virtual void OnGotFocus(FocusChangedEventArgs e)
Parameters
OnLostFocus(FocusChangedEventArgs)
An event announcing that the buttons is no longer focused on this element
protected virtual void OnLostFocus(FocusChangedEventArgs e)
Parameters
OnPreviewButtonDown(ButtonEventArgs)
An event reporting a button was pressed.
protected virtual void OnPreviewButtonDown(ButtonEventArgs e)
Parameters
OnPreviewButtonUp(ButtonEventArgs)
An event reporting a button was released.
protected virtual void OnPreviewButtonUp(ButtonEventArgs e)
Parameters
OnRender(DrawingContext)
public virtual void OnRender(DrawingContext dc)
Parameters
OnTouchDown(TouchEventArgs)
protected virtual void OnTouchDown(TouchEventArgs e)
Parameters
OnTouchGestureChanged(TouchGestureEventArgs)
protected virtual void OnTouchGestureChanged(TouchGestureEventArgs e)
Parameters
OnTouchGestureEnded(TouchGestureEventArgs)
protected virtual void OnTouchGestureEnded(TouchGestureEventArgs e)
Parameters
OnTouchGestureStarted(TouchGestureEventArgs)
protected virtual void OnTouchGestureStarted(TouchGestureEventArgs e)
Parameters
OnTouchMove(TouchEventArgs)
protected virtual void OnTouchMove(TouchEventArgs e)
Parameters
OnTouchUp(TouchEventArgs)
protected virtual void OnTouchUp(TouchEventArgs e)
Parameters
PointToClient(ref int, ref int)
public void PointToClient(ref int x, ref int y)
Parameters
PointToScreen(ref int, ref int)
We are deviating little from their desktop counter parts, mostly for simplicity and perf.
public void PointToScreen(ref int x, ref int y)
Parameters
RaiseEvent(RoutedEventArgs)
public void RaiseEvent(RoutedEventArgs args)
Parameters
argsRoutedEventArgs
RenderRecursive(DrawingContext)
protected virtual void RenderRecursive(DrawingContext dc)
Parameters
SetMargin(int)
public void SetMargin(int length)
Parameters
lengthint
SetMargin(int, int, int, int)
public void SetMargin(int left, int top, int right, int bottom)
Parameters
UpdateLayout()
Call this method to ensure that the whoel subtree of elements that includes this UIElement is properly updated.
public void UpdateLayout()
Remarks
This ensures that UIElements with IsMeasureInvalid or IsArrangeInvalid will get call to their MeasureOverride and ArrangeOverride, 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 UIElement 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
IsEnabledChanged
public event PropertyChangedEventHandler IsEnabledChanged
Event Type
IsVisibleChanged
public event PropertyChangedEventHandler IsVisibleChanged
Event Type
TouchDown
public event TouchEventHandler TouchDown
Event Type
TouchGestureChanged
public event TouchGestureEventHandler TouchGestureChanged
Event Type
TouchGestureEnd
public event TouchGestureEventHandler TouchGestureEnd
Event Type
TouchGestureStart
public event TouchGestureEventHandler TouchGestureStart
Event Type
TouchMove
public event TouchEventHandler TouchMove
Event Type
TouchUp
public event TouchEventHandler TouchUp