Windows.UI.Xaml.UIElement

June 22, 2022 ยท View on GitHub

-description

UIElement is a base class for most of the Windows Runtime UI objects that have visual appearance and can process basic input as part of your app's user interface.

-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:

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:

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:

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

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.

Version history

Windows versionSDK versionValue added
160714393AccessKey
160714393AccessKeyDisplayDismissed
160714393AccessKeyDisplayRequested
160714393AccessKeyInvoked
160714393AccessKeyScopeOwner
160714393ContextCanceled
160714393ContextFlyout
160714393ContextRequested
160714393ExitDisplayModeOnAccessKeyInvoked
160714393IsAccessKeyScope
170315063GettingFocus
170315063GettingFocusEvent
170315063HighContrastAdjustment
170315063KeyTipHorizontalOffset
170315063KeyTipPlacementMode
170315063KeyTipVerticalOffset
170315063Lights
170315063LosingFocus
170315063LosingFocusEvent
170315063NoFocusCandidateFound
170315063NoFocusCandidateFoundEvent
170315063StartBringIntoView
170315063StartBringIntoView(BringIntoViewOptions)
170315063TabFocusNavigation
170315063XYFocusDownNavigationStrategy
170315063XYFocusKeyboardNavigation
170315063XYFocusLeftNavigationStrategy
170315063XYFocusRightNavigationStrategy
170315063XYFocusUpNavigationStrategy
170916299CharacterReceived
170916299CharacterReceivedEvent
170916299GetChildrenInTabFocusOrder
170916299KeyboardAccelerators
170916299OnProcessKeyboardAccelerators
170916299PreviewKeyDown
170916299PreviewKeyDownEvent
170916299PreviewKeyUp
170916299PreviewKeyUpEvent
170916299ProcessKeyboardAccelerators
170916299TryInvokeKeyboardAccelerator
180317134BringIntoViewRequested
180317134BringIntoViewRequestedEvent
180317134ContextRequestedEvent
180317134KeyboardAcceleratorPlacementMode
180317134KeyboardAcceleratorPlacementTarget
180317134KeyTipTarget
180317134OnBringIntoViewRequested
180317134OnKeyboardAcceleratorInvoked
180317134RegisterAsScrollPort
180917763CanBeScrollAnchor
180917763CenterPoint
180917763OpacityTransition
180917763PopulatePropertyInfo
180917763PopulatePropertyInfoOverride
180917763Rotation
180917763RotationAxis
180917763RotationTransition
180917763Scale
180917763ScaleTransition
180917763StartAnimation
180917763StopAnimation
180917763TransformMatrix
180917763Translation
180917763TranslationTransition
190318362ActualOffset
190318362ActualSize
190318362Shadow
190318362UIContext
190318362XamlRoot

-examples

-see-also

DependencyObject, FrameworkElement, Events and routed events overview, Dependency properties overview, Drag and drop sample, Basic input sample, Transform3D animations sample