UIElement 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
UIElement 是大多数Windows 运行时 UI 对象的基类,这些对象具有视觉外观,并且可以作为应用用户界面的一部分处理基本输入。
public ref class UIElement : DependencyObject
public ref class UIElement : DependencyObject, IAnimationObject
public ref class UIElement : DependencyObject, IAnimationObject, IVisualElement
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject, IAnimationObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UIElement : DependencyObject, IAnimationObject, IVisualElement
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject, IAnimationObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class UIElement : DependencyObject, IAnimationObject, IVisualElement
Public Class UIElement
Inherits DependencyObject
Public Class UIElement
Inherits DependencyObject
Implements IAnimationObject
Public Class UIElement
Inherits DependencyObject
Implements IAnimationObject, IVisualElement
- 继承
- 派生
- 属性
- 实现
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
注解
UIElement 是一个基元素:它是许多其他Windows 运行时类继承的类,以支持 XAML UI 元素模型。 UIElement 定义的属性、方法和事件由数百个其他Windows 运行时类继承。
尽管 UIElement (GotFocus、 LostFocus) 定义焦点报告事件,但 UIElement 不定义用于以编程方式设置焦点的 API。 此功能由 Control 类定义。
UIElement 不公开公共构造函数。 通常,不会直接从 UIElement 或 FrameworkElement 派生类。 派生自定义类更常用的基类包括以下类:
- 未密封 (的特定控件,例如 TextBox)
- 控件基类 (Control、 ContentControl、 UserControl)
- 页面、框架) (导航元素
- 面板类 (基类 Panel 或特定的非密封实现,例如 Grid)
UIElement 类用作 Windows 运行时 API 中许多属性和方法的类型参数。 例如,Border 的 Child 属性采用单个 UIElement,它表示绘制边框的元素。 可以为此类属性提供任何 UIElement 派生元素,包括定义的自定义控件。
UIElementCollection 类提供 UIElement 项的强类型集合。 UIElementCollection 用作包含多个子元素的对象的属性的类型,例如,对于任何 Panel 类的 Children 属性。
UIElement API 和功能
UIElement 扩展了 DependencyObject(另一个基元素),并添加了对各种Windows 运行时功能区域的支持。
用于响应用户交互的输入和事件
UI 中可见元素的很多输入行为都是在 UIElement 类中定义的。 这包括键盘、鼠标、触摸、拖放和焦点交互的事件。 有关详细信息,请参阅 处理指针输入、 键盘交互和 自定义用户交互。
支持输入和用户交互的 UIElement 的突出 API:
- 指针事件:PointerPressed、 PointerReleased、 PointerMoved、 PointerEntered、 PointerExited
- 键处理事件:KeyDown、 KeyUp
- Focus:GotFocus、 LostFocus
- 指针捕获:CapturePointer、 PointerCanceled、 PointerCaptureLost、 ReleasePointerCapture、 PointerCaptures
- 拖放:DragOver、 Drop、 DragEnter、 DragLeave、 AllowDrop
- 影响基本输入处理方式的属性:IsHitTestVisible、 AllowDrop
手势和操作
手势和操作也是处理输入和用户交互的一种方法。 API 在此处单独列出,因为这些事件表示系统如何与设备级输入操作交互,并将其解释为用户交互。 操作是处理动态多点触控交互(如收缩和拉伸)的一种方法。 手势和操作共同提供用于与 UWP 应用的触摸交互的触摸模式。 有关详细信息,请参阅 自定义用户交互 和 触摸交互设计。
支持手势和操作的 UIElement 的突出 API:
- 手势事件:DoubleTapped、 Holding、 RightTapped、 Tappped
- Manipulation 事件:ManipulationCompleted、 ManipulationDelta、 ManipulationInertiaStarting、 ManipulationStarted、 ManipulationStarting
- 影响处理手势和操作方式的属性:IsHoldingEnabled 和其他 Is*Enabled, ManipulationMode
基本外观
Visibility 和 Opacity 属性通常用于调整 UI 中元素的外观,尤其是在样式、模板和视觉状态中。 Clip、RenderTransform 和 Transitions 属性都可用于生成 UI 元素的交互和不同的外观。
基本布局
UIElement 类为具有 DesiredSize 和 Arrange 和 Measure 方法等属性的布局特征提供起点。 FrameworkElement 添加了更多布局功能。 有关详细信息,请参阅使用 XAML 和 FrameworkElement定义布局。
路由事件
UIElement 的大多数输入事件都是 路由事件。 路由事件启用内置的事件处理通知系统,以便父对象可以在事件仍未处理的情况下处理来自对象树中子对象的输入事件。 此输入事件行为对于输入区域分组和控件合成非常有用。 有关详细信息,请参阅事件和路由事件概述。
支持路由事件的 UIElement 的突出 API: AddHandler、 RemoveHandler、*Event 属性。
其他平台支持
- OnCreateAutomationPeer 使类能够将自定义 AutomationPeer 用于其 Microsoft UI 自动化支持。
- RenderTransform、 TransformToVisual、 Projection、 CompositeMode、 CacheMode 和 FindSubElementsForTouchTargeting 对于高级 UI 布局方案非常有用。
UIElement 依赖属性
UIElement 基元素类的许多读写属性都是依赖属性。 依赖属性支持使用 C++、C# 或 Visual Basic 的 UWP 应用的某些基本编程模型功能,例如样式和模板、数据绑定、XAML 资源引用和属性更改逻辑。 有关依赖属性及其支持的功能的详细信息,请参阅 依赖属性概述。
UIElement 派生类
唯一直接从 UIElement 派生Windows 运行时类是 FrameworkElement。 有关派生自 FrameworkElement 的类的列表,请参阅 FrameworkElement 参考主题的“ FrameworkElement 派生类”部分。
版本历史记录
Windows 版本 | SDK 版本 | 增值 |
---|---|---|
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 | 光 |
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 | 旋转 |
1809 | 17763 | RotationAxis |
1809 | 17763 | RotationTransition |
1809 | 17763 | 缩放 |
1809 | 17763 | ScaleTransition |
1809 | 17763 | StartAnimation |
1809 | 17763 | StopAnimation |
1809 | 17763 | TransformMatrix |
1809 | 17763 | 翻译 |
1809 | 17763 | TranslationTransition |
1903 | 18362 | ActualOffset |
1903 | 18362 | ActualSize |
1903 | 18362 | Shadow |
1903 | 18362 | UIContext |
1903 | 18362 | XamlRoot |
属性
方法
事件
AccessKeyDisplayDismissed |
在不应再显示访问密钥时发生。 |
AccessKeyDisplayRequested |
当用户请求显示访问密钥时发生。 |
AccessKeyInvoked |
当用户完成访问密钥序列时发生。 |
BringIntoViewRequested |
在此元素或其后代之一上调用 StartBringIntoView 时发生。 |
CharacterReceived |
输入队列接收到单个组合字符时发生。 |
ContextCanceled |
当上下文输入手势继续转换为操作手势时发生,以通知元素不应打开上下文浮出控件。 |
ContextRequested |
当用户完成上下文输入手势(例如右键单击)时发生。 |
DoubleTapped |
当此元素的命中测试区域发生其他未经处理的 DoubleTap 交互时发生。 |
DragEnter |
当输入系统报告具有此元素作为目标的基础拖动事件时发生。 |
DragLeave |
当输入系统报告具有此元素作为原点的基础拖动事件时发生。 |
DragOver |
在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。 |
DragStarting |
在启动拖动操作时发生。 |
Drop |
在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。 |
DropCompleted |
结束此元素作为源的拖放操作时发生。 |
GettingFocus |
在 UIElement 接收焦点之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。 |
GotFocus |
在 UIElement 收到焦点时发生。 此事件是异步引发的,因此焦点可以在浮升完成之前再次移动。 |
Holding |
当此元素的命中测试区域发生其他未处理的 保持 交互时发生。 |
KeyDown |
当 UIElement 具有焦点时按下键盘键时发生。 |
KeyUp |
在 UIElement 具有焦点时释放键盘键时发生。 |
LosingFocus |
在 UIElement 失去焦点之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。 |
LostFocus |
当 UIElement 失去焦点时发生。 此事件以异步方式引发,因此焦点可以在冒泡完成之前再次移动。 |
ManipulationCompleted |
在 UIElement 上的操作完成时发生。 |
ManipulationDelta |
当输入设备在操作期间更改位置时发生。 |
ManipulationInertiaStarting |
在输入设备在操作期间与 UIElement 对象失去联系和延迟开始时发生。 |
ManipulationStarted |
在输入设备在 UIElement 上开始操作时发生。 |
ManipulationStarting |
在首次创建操作处理器时发生。 |
NoFocusCandidateFound |
当用户尝试通过制表键或方向箭头 (移动焦点) ,但焦点不会移动时发生,因为移动方向上找不到焦点候选项。 |
PointerCanceled |
当进行接触的指针异常失去接触时发生。 |
PointerCaptureLost |
当此元素以前持有的指针捕获移动到另一个元素或其他位置时发生。 |
PointerEntered |
当指针进入此元素的命中测试区域时发生。 |
PointerExited |
当指针离开此元素的命中测试区域时发生。 |
PointerMoved |
当指针在指针停留在此元素的命中测试区域内时移动时发生。 |
PointerPressed |
当指针设备在此元素中启动 Press 操作时发生。 |
PointerReleased |
在释放之前启动 按下 操作的指针设备时发生,同时在此元素中。 请注意, 不保证按下 操作的结尾会触发 PointerReleased 事件;可能会触发其他事件。 有关详细信息,请参阅备注。 |
PointerWheelChanged |
在指针滚轮的增量值更改时发生。 |
PreviewKeyDown |
当 UIElement 具有焦点时按下键盘键时发生。 |
PreviewKeyUp |
在 UIElement 具有焦点时释放键盘键时发生。 |
ProcessKeyboardAccelerators |
按下 键盘快捷方式 (或快捷键) 时发生。 |
RightTapped |
当指针位于 元素上时发生右点击输入刺激时发生。 |
Tapped |
在此元素的命中测试区域上发生未经处理的 点击 交互时发生。 |
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈