WinUI 3 WinRT 命名空间基础
Windows app sdk API 较多比较混乱,本文旨在理清相关的 WinRT 命名空间的基础知识,帮助开发者更好地理解 WinUI 3 的 API。
继承关系
基本继承链
IUnknown (Win32 COM ABI defined in
unknwn.h
) / Windows.Foundation.IUnkown (WinRT Interface wrapper for Win32) -> IInspectable (Win32 COM ABI defined ininspectable.h
) / Windows.Foundation.IInspectable (WinRT Interface wrapper for Win32) -> Microsoft.UI.Xaml.DependencyObject -> Microsoft.UI.Xaml.UIElement -> Microsoft.UI.Xaml.FrameworkElement -> ( ... )
描述
DependencyObject
类在其许多派生类上启用依赖属性系统服务,并且是许多重要 UI 相关类(如 UIElement、 Geometry、 FrameworkTemplate、 Style 和 ResourceDictionary)的直接基类。对象通过声明实现此类来参与依赖属性系统,这将允许对象在运行时注册依赖属性到依赖属性系统。
依赖属性系统的主要功能是计算属性值,并提供有关已更改的值的系统通知。参与依赖属性系统的另一个关键类是 DependencyProperty
。DependencyProperty
允许将依赖属性注册到属性系统中,而 DependencyObject 作为基类,实现了 DependencyObject
基类的对象可以使用和设置依赖属性。
DependencyObject
是多个派生类的直接父类,这些类是应用程序和 XAML UI 编程模型的基础。下面是一些值得注意的派生类:
- UIElement (UI元素):这是大多数可以处理 UI 输入的视觉对象的基类。FrameworkElement 在这个层次结构中进一步(
FrameworkElement
的直接基类是UIElement
), Control 也是如此 (Control
的直接基类是FrameworkElement
)。因此在 Windows 运行时中,有数百个控件和其他类的类层次结构中都具有 UIElement 类。 - XAML 样式系统支持类: FrameworkTemplate (ControlTemplate、 DataTemplate、 ItemsPanelTemplate) 、 Style、 SetterBase (Setter) 、 ToolTipTemplateSettings 和其他 TemplateSettings 的父级。
- 视觉状态模型: Transition、 VisualState、 VisualStateGroup、 VisualStateManager、 VisualTransition。
- 数据绑定支持: BindingBase (Binding) 、 CollectionViewSource、 PropertyPath、 RelativeSource 的父级。
- 故事板动画: TimeLine (Storyboard 的父级、类型化动画、主题动画) 、输入关键帧 (如 ColorKeyFrame 、 KeySpline、 EasingFunctionBase)。
- XAML 图形和呈现基元: Brush、 Geometry、 GeneralTransform、 GradientStop、 PathFigure、 PathSegment、 Projection。
- 图像处理和呈现表面互操作: ImageSource (BitmapSource、 RenderTargetBitmap、 SurfaceImageSource 和其他) 的父级。
- Window:表示应用顶级界面的窗口,可以承载页面等元素,页面也必须由 Window 承载。
- FlyoutBase (Flyout 和 MenuFlyout) 的父级。
- ResourceDictionary:在 XAML 中定义资源字典。
- TextElement: Block 和 Inline 的父级,这些元素又是用于 TextBlock 内容或富文本元素的文本元素的基类。
- AutomationPeer:代表 XAML 控件提供支持给 Microsoft UI Automation 监听器的 Microsoft UI Automation 系列类的基类。同时也是 IRawElementProviderSimple 的基类。
- 杂项: CacheMode、 ColumnDefinition、 DependencyObjectCollection、 InputScope、 InputScopeName、 PageStackEntry、 PrintDocument、 RowDefinition、 TriggerAction、 TriggerBase。