-api-id | -api-type |
---|---|
T:Windows.UI.Xaml.UIElement |
winrt class |
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.
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 extends DependencyObject, which is another base element, and adds support for various Windows Runtime feature areas.
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 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
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.
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.
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.
- 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.
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.
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.
Windows version | SDK version | Value added |
---|---|---|
1607 | 14393 | AccessKey |
1607 | 14393 | AccessKeyDisplayDismissed |
1607 | 14393 | AccessKeyDisplayRequested |
1607 | 14393 | AccessKeyInvoked |
1607 | 14393 | AccessKeyScopeOwner |
1607 | 14393 | ContextCanceled |
1607 | 14393 | ContextFlyout |
1607 | 14393 | ContextRequested |
1607 | 14393 | ExitDisplayModeOnAccessKeyInvoked |
1607 | 14393 | IsAccessKeyScope |
1703 | 15063 | GettingFocus |
1703 | 15063 | GettingFocusEvent |
1703 | 15063 | HighContrastAdjustment |
1703 | 15063 | KeyTipHorizontalOffset |
1703 | 15063 | KeyTipPlacementMode |
1703 | 15063 | KeyTipVerticalOffset |
1703 | 15063 | Lights |
1703 | 15063 | LosingFocus |
1703 | 15063 | LosingFocusEvent |
1703 | 15063 | NoFocusCandidateFound |
1703 | 15063 | NoFocusCandidateFoundEvent |
1703 | 15063 | StartBringIntoView |
1703 | 15063 | StartBringIntoView(BringIntoViewOptions) |
1703 | 15063 | TabFocusNavigation |
1703 | 15063 | XYFocusDownNavigationStrategy |
1703 | 15063 | XYFocusKeyboardNavigation |
1703 | 15063 | XYFocusLeftNavigationStrategy |
1703 | 15063 | XYFocusRightNavigationStrategy |
1703 | 15063 | XYFocusUpNavigationStrategy |
1709 | 16299 | CharacterReceived |
1709 | 16299 | CharacterReceivedEvent |
1709 | 16299 | GetChildrenInTabFocusOrder |
1709 | 16299 | KeyboardAccelerators |
1709 | 16299 | OnProcessKeyboardAccelerators |
1709 | 16299 | PreviewKeyDown |
1709 | 16299 | PreviewKeyDownEvent |
1709 | 16299 | PreviewKeyUp |
1709 | 16299 | PreviewKeyUpEvent |
1709 | 16299 | ProcessKeyboardAccelerators |
1709 | 16299 | TryInvokeKeyboardAccelerator |
1803 | 17134 | BringIntoViewRequested |
1803 | 17134 | BringIntoViewRequestedEvent |
1803 | 17134 | ContextRequestedEvent |
1803 | 17134 | KeyboardAcceleratorPlacementMode |
1803 | 17134 | KeyboardAcceleratorPlacementTarget |
1803 | 17134 | KeyTipTarget |
1803 | 17134 | OnBringIntoViewRequested |
1803 | 17134 | OnKeyboardAcceleratorInvoked |
1803 | 17134 | RegisterAsScrollPort |
1809 | 17763 | CanBeScrollAnchor |
1809 | 17763 | CenterPoint |
1809 | 17763 | OpacityTransition |
1809 | 17763 | PopulatePropertyInfo |
1809 | 17763 | PopulatePropertyInfoOverride |
1809 | 17763 | Rotation |
1809 | 17763 | RotationAxis |
1809 | 17763 | RotationTransition |
1809 | 17763 | Scale |
1809 | 17763 | ScaleTransition |
1809 | 17763 | StartAnimation |
1809 | 17763 | StopAnimation |
1809 | 17763 | TransformMatrix |
1809 | 17763 | Translation |
1809 | 17763 | TranslationTransition |
1903 | 18362 | ActualOffset |
1903 | 18362 | ActualSize |
1903 | 18362 | Shadow |
1903 | 18362 | UIContext |
1903 | 18362 | XamlRoot |
DependencyObject, FrameworkElement, Events and routed events overview, Dependency properties overview, Drag and drop sample, Basic input sample, Transform3D animations sample