UIElement UIElement UIElement UIElement Class
Definition
Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Prerelease APIs are identified by a Prerelease label.
public : class UIElement : DependencyObject, IUIElement, IUIElement2, IUIElement3, IUIElement4, IUIElement5, IUIElement7, IUIElementOverrides
struct winrt::Windows::UI::Xaml::UIElement : DependencyObject, IUIElement, IUIElement2, IUIElement3, IUIElement4, IUIElement5, IUIElement7, IUIElementOverrides
public class UIElement : DependencyObject, IUIElement, IUIElement2, IUIElement3, IUIElement4, IUIElement5, IUIElement7, IUIElementOverrides
Public Class UIElement Inherits DependencyObject Implements IUIElement, IUIElement2, IUIElement3, IUIElement4, IUIElement5, IUIElement7, IUIElementOverrides
- Inheritance
- Attributes
Device family |
Windows 10 (introduced v10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
UIElement is a base element: it's a class that many other Windows Runtime classes inherit from in order to support the XAML UI element model. Properties, methods and events that UIElement defines are inherited by hundreds of other Windows Runtime classes.
Although UIElement defines the events for focus reporting (GotFocus, LostFocus ), UIElement does not define an API for programmatically setting the focus. This capability is defined by the Control class.
UIElement does not expose a public constructor. Typically, you don't derive classes from either UIElement or FrameworkElement directly. More typically used base classes for derived custom classes are these classes:
- Specific controls that are not sealed (for example, TextBox )
- Control base classes (Control, ContentControl, UserControl )
- Navigation elements (Page, Frame )
- Panel classes (the base class Panel, or specific non-sealed implementations such as Grid )
The UIElement class is used as the type parameter of many properties and methods in the Windows Runtime API. For example, the Child property of Border takes a single UIElement, which represents the element that the Border is drawn around. You can provide any UIElement -derived element for such a property, including custom controls that you define.
The UIElementCollection class provides a strongly typed collection of UIElement items. UIElementCollection is used as a type for properties of objects that contain several child elements, for example for the Children property of any Panel class.
UIElement API and features
UIElement extends DependencyObject, which is another base element, and adds support for various Windows Runtime feature areas.
Input, and events for responding to user interaction
Much of the input behavior for visible elements in a UI is defined in the UIElement class. This includes the events for keyboard, mouse, touch, drag-drop, and focus interactions. For more info, see Handle pointer input, Keyboard interactions, and Custom user interactions.
Prominent API of UIElement that support input and user interaction:
- Pointer events: PointerPressed, PointerReleased, PointerMoved, PointerEntered, PointerExited
- Key handling events: KeyDown, KeyUp
- Focus: GotFocus, LostFocus
- Pointer capture: CapturePointer, PointerCanceled, PointerCaptureLost, ReleasePointerCapture, PointerCaptures
- Drag-drop: DragOver, Drop, DragEnter, DragLeave, AllowDrop
- Properties that influence how basic input is processed: IsHitTestVisible, AllowDrop
Gestures and manipulations
Gestures and manipulations are also a way to handle input and user interaction. The API are listed out separately here because these events represent how the system interacts with device-level input actions and interprets them as a user interaction. Manipulations are a way to handle dynamic multi-touch interactions such as pinching and stretching. Together, the gestures and manipulations provide the touch patterns for touch interaction with UWP app. For more info, see Custom user interactions and Touch interaction design.
Prominent API of UIElement that support gestures and manipulations:
- Gesture events: DoubleTapped, Holding, RightTapped, Tapped
- Manipulation events: ManipulationCompleted, ManipulationDelta, ManipulationInertiaStarting, ManipulationStarted, ManipulationStarting
- Properties that influence how gestures and manipulations are processed: IsHoldingEnabled and other Is*Enabled, ManipulationMode
Basic appearance
The Visibility and Opacity properties are frequently used to adjust the appearance of an element in your UI, especially within styles, templates, and visual states. The Clip, RenderTransform, and Transitions properties are each useful for producing interactions and different looks for your UI elements.
Basic layout
The UIElement class provides a starting point for layout characteristics with properties such as DesiredSize and the Arrange and Measure methods. FrameworkElement adds more layout capabilities. For more info, see Define layouts with XAML and FrameworkElement.
Routed events
Most of the input events of UIElement are routed events. A routed event enables a built-in event handling notification system, so that a parent object can handle input events from child objects in the object tree if the event remains unhandled. This input event behavior is useful for input area grouping, and for control compositing. For more info, see Events and routed events overview.
Prominent API of UIElement that support routed events: AddHandler, RemoveHandler, **Event* properties.
Other platform support
- OnCreateAutomationPeer enables a class to use a custom AutomationPeer for its Microsoft UI Automation support.
- RenderTransform, TransformToVisual, Projection, CompositeMode, CacheMode and FindSubElementsForTouchTargeting are useful for advanced UI layout scenarios.
UIElement dependency properties
Many of the read-write properties of the UIElement base element class are dependency properties. Dependency properties support some of the basic programming model features for a UWP app using C++, C#, or Visual Basic, such as styles and templates, data binding, XAML resource references, and property-changed logic. For more info on dependency properties and the features they support, see Dependency properties overview.
UIElement derived classes
The only Windows Runtime class that derives directly from UIElement is FrameworkElement. For a list of the classes that derive from FrameworkElement, see the "FrameworkElement derived classes" section of the FrameworkElement reference topic.
Properties
Methods
Events
AccessKeyDisplayDismissed AccessKeyDisplayDismissed AccessKeyDisplayDismissed AccessKeyDisplayDismissed |
Occurs when the access key sequence is complete to notify controls that they should hide access key visuals. |
AccessKeyDisplayRequested AccessKeyDisplayRequested AccessKeyDisplayRequested AccessKeyDisplayRequested |
Occurs when the access key sequence is started to notify controls that they should show access key visuals. |
AccessKeyInvoked AccessKeyInvoked AccessKeyInvoked AccessKeyInvoked |
Occurs when a user completes an access key sequence to notify the element that the access key action should be invoked. |
BringIntoViewRequested BringIntoViewRequested BringIntoViewRequested BringIntoViewRequested |
Prerelease. Occurs when StartBringIntoView is called on this element or one of its descendants. |
CharacterReceived CharacterReceived CharacterReceived CharacterReceived |
Occurs when a single, composed character is received by the input queue. |
ContextCanceled ContextCanceled ContextCanceled ContextCanceled |
Occurs when a context input gesture continues into a manipulation gesture, to notify the element that the context flyout should not be opened. |
ContextRequested ContextRequested ContextRequested ContextRequested |
Occurs when the user has completed a context input gesture, such as a right-click. |
DoubleTapped DoubleTapped DoubleTapped DoubleTapped |
Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of this element. |
DragEnter DragEnter DragEnter DragEnter |
Occurs when the input system reports an underlying drag event with this element as the target. |
DragLeave DragLeave DragLeave DragLeave |
Occurs when the input system reports an underlying drag event with this element as the origin. |
DragOver DragOver DragOver DragOver |
Occurs when the input system reports an underlying drag event with this element as the potential drop target. |
DragStarting DragStarting DragStarting DragStarting |
Occurs when a drag operation is initiated. |
Drop Drop Drop Drop |
Occurs when the input system reports an underlying drop event with this element as the drop target. |
DropCompleted DropCompleted DropCompleted DropCompleted |
Occurs when a drag-and-drop operation is ended. |
GettingFocus GettingFocus GettingFocus GettingFocus |
Occurs before a UIElement receives focus. |
GotFocus GotFocus GotFocus GotFocus |
Occurs when a UIElement receives focus. |
Holding Holding Holding Holding |
Occurs when an otherwise unhandled Hold interaction occurs over the hit test area of this element. |
KeyDown KeyDown KeyDown KeyDown |
Occurs when a keyboard key is pressed while the UIElement has focus. |
KeyUp KeyUp KeyUp KeyUp |
Occurs when a keyboard key is released while the UIElement has focus. |
LosingFocus LosingFocus LosingFocus LosingFocus |
Occurs before a UIElement loses focus. |
LostFocus LostFocus LostFocus LostFocus |
Occurs when a UIElement loses focus. |
ManipulationCompleted ManipulationCompleted ManipulationCompleted ManipulationCompleted |
Occurs when a manipulation on the UIElement is complete. |
ManipulationDelta ManipulationDelta ManipulationDelta ManipulationDelta |
Occurs when the input device changes position during a manipulation. |
ManipulationInertiaStarting ManipulationInertiaStarting ManipulationInertiaStarting ManipulationInertiaStarting |
Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. |
ManipulationStarted ManipulationStarted ManipulationStarted ManipulationStarted |
Occurs when an input device begins a manipulation on the UIElement. |
ManipulationStarting ManipulationStarting ManipulationStarting ManipulationStarting |
Occurs when the manipulation processor is first created. |
NoFocusCandidateFound NoFocusCandidateFound NoFocusCandidateFound NoFocusCandidateFound |
Occurs when a user attempts to move focus (via tab or directional arrows), but focus doesn't move because no focus candidate is found in the direction of movement. |
PointerCanceled PointerCanceled PointerCanceled PointerCanceled |
Occurs when a pointer that made contact abnormally loses contact. |
PointerCaptureLost PointerCaptureLost PointerCaptureLost PointerCaptureLost |
Occurs when pointer capture previously held by this element moves to another element or elsewhere. |
PointerEntered PointerEntered PointerEntered PointerEntered |
Occurs when a pointer enters the hit test area of this element. |
PointerExited PointerExited PointerExited PointerExited |
Occurs when a pointer leaves the hit test area of this element. |
PointerMoved PointerMoved PointerMoved PointerMoved |
Occurs when a pointer moves while the pointer remains within the hit test area of this element. |
PointerPressed PointerPressed PointerPressed PointerPressed |
Occurs when the pointer device initiates a Press action within this element. |
PointerReleased PointerReleased PointerReleased PointerReleased |
Occurs when the pointer device that previously initiated a Press action is released, while within this element. Note that the end of a Press action is not guaranteed to fire a PointerReleased event; other events may fire instead. For more info, see Remarks. |
PointerWheelChanged PointerWheelChanged PointerWheelChanged PointerWheelChanged |
Occurs when the delta value of a pointer wheel changes. |
PreviewKeyDown PreviewKeyDown PreviewKeyDown PreviewKeyDown |
Occurs when a keyboard key is pressed while the UIElement has focus. |
PreviewKeyUp PreviewKeyUp PreviewKeyUp PreviewKeyUp |
Occurs when a keyboard key is released while the UIElement has focus. |
ProcessKeyboardAccelerators ProcessKeyboardAccelerators ProcessKeyboardAccelerators ProcessKeyboardAccelerators |
Occurs when a keyboard shortcut (or accelerator) is pressed. |
RightTapped RightTapped RightTapped RightTapped |
Occurs when a right-tap input stimulus happens while the pointer is over the element. |
Tapped Tapped Tapped Tapped |
Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element. |