WPF基础四:UI相关的类 (1) 父类

目录

一)控件的分类与派生关系

二)UI

2.1)UI父类

2.1.1 Object类

2.1.2 DispatcherObject类

2.1.3 DependencyObject类

2.1.4 Visual类

2.1.5 UIElement 类

2.1.6 FrameworkElement

2.1.7 Control 类

总结:


一)控件的分类与派生关系

控件类型控件名称所属说明派生特点
布局控件CanvasPanel定义一个区域,可在其中使用相对于 Canvas 区域的坐标以显式方式来定位子元素。Panel->Canvas内容属性为Children,内容可以是多个元素,该类元素控制布局
DockPanelPanel定义一个区域,从中可以按相对位置水平或垂直排列各个子元素。Panel->DockPanel
GridPanel定义由列和行组成的灵活的网格区域。Panel->Grid
PanelPanel为所有Panel元素提供基类。使用 Panel 元素放置和排列WPF应用程序中的子对象。Panel
StackPanelPanel将子元素排列成水平或垂直的一行。Panel->StackPanel
TabPanelPanel处理 TabItem 上的 TabControl 对象的布局。Panel->TabPanel
ToolBarOverflowPanelPanel用来排列溢出的 ToolBar 项。Panel->ToolBarOverflowPanel
ToolBarPanelPanel在 ToolBar 中排列 ToolBar 项。Panel->ToolBarPanel
UniformGridPanel提供一种在网格(网格中的所有单元格都具有相同的大小)中排列内容的方法。Panel->UniformGrid
VirtualizingPanelPanel为虚拟化其子数据集合的 Panel 元素提供一个框架。 这是一个抽象类。Panel->VirtualizingPanel
VirtualizingStackPanelPanel在水平或垂直的一行中排列并显示内容。Panel->VirtualizingPanel->VirtualizingStackPanel
WrapPanelPanel按从左到右的顺序位置定位子元素,在包含框的边缘处将内容切换到下一行。 后续排序按照从上至下或从右至左的顺序进行,具体取决于 Orientation 属性的值。Panel->WrapPanel
内容控件BaseButtonContentControl表示所有 Button 控件的基类。ContentControl->BaseButton只能由单一元素充当内容
ButtonContentControl按钮ContentControl->BaseButton->Button
ToggleButtonContentControl可切换状态的控件基类ContentControl->BaseButton->ToggleButton
CheckBoxContentControl用户可以选择和清除的控件。ContentControl->BaseButton->ToggleButton->CheckBox
ComboBoxItemContentControl在 ComboBox 内实现可选择的项ContentControl->ListBoxItem->ComboBoxItem
ContentControl ContentControl包含一段任意类型内容的控件。ContentControl
Frame ContentControl框架是一种支持导航的内容控件。ContentControl->Frame
GridViewColumnHeaderContentControl表示 GridViewColumn 的列标题。ContentControll->ButtonBasel->GridViewColumnHeader
GroupItemContentControl显示为组生成的可视子树的根。ContentControl->GroupItem
LabelContentControl文本标签ContentControl->Label
ListBoxItemContentControl表示 ListBox 中的可选项。ContentControl->ListBoxItem
ListViewItem ContentControl表示 ListView 控件中的一个项ContentControl->ListBoxItem->ListViewItem
NavigationWindowContentControl表示支持内容导航的窗口。ContentControl->Window->NavigationWindow
PasswordBoxContentControl密码控件ContentControl->PasswordBox
RadioButtonContentControl表示可由用户选择但不能清除的按钮。 可以通过单击来设置 IsChecked 的 RadioButton 属性,但只能以编程方式清除该属性。ContentControl->ButtonBase->ToggleButton->RadioButton
RepeatButtonContentControl表示从按下按钮到释放按钮的时间内重复引发其 Click 事件的控件。ContentControl->ButtonBase->RepeatButton
StatusBarItemContentControl表示 StatusBar 控件的项。ContentControl->StatusBarItem
ScrollViewerContentControl表示可包含其他可视元素的可滚动区域。ContentControl->ScrollViewer
ToolTipContentControl表示一个控件,该控件可创建一个弹出窗口,以便在界面中显示元素的信息。ContentControl->ToolTip
UserControlContentControl提供一种创建控件的简单方法。ContentControl->UserControl
WindowContentControl窗体ContentControl->Window
带标题内容控件ExpanderHeaderedContentControl表示一种控件,该控件显示具有可折叠内容显示窗口的标题。HeaderedContentControl->Expander内容属性为Content和Herder,均只能容纳单一元素作为其内容
GroupBoxHeaderedContentControl表示一个控件,该控件用于创建具有用户界面 (UI) 内容边框和标题的容器。HeaderedContentControl->GroupBox
HeaderedContentControl HeaderedContentControl为包含单项内容并具有标头的所有控件提供基实现。HeaderedContentControl
TabItemHeaderedContentControl表示 TabControl 内某个可选择的项。HeaderedContentControl->TabItem
条目控件ContextMenuItemsControl表示一个弹出菜单ItemsControl->MenuBase->ContextMenu内容属性为Items或ItemsSource。每种ItemsControl都对应有自己的条目容器(Items Container)
ComboBoxItemsControl带有下拉列表的选择控件ItemsControl->Selector->ComboBox
DataGridItemsControl表示用于在可自定义的网格中显示数据的控件。ItemsControl->Selector->MultiSelector->DataGrid
ItemsControlItemsControl表示可用于呈现一组项的控件。ItemsControl
ListBoxItemsControl包含可选项列表。ItemsControl->Selector->ListBox
ListViewItemsControl表示用于显示数据项列表的控件。ItemsControl->Selector->ListBox->ListView
MenuBaseItemsControl表示一个控件,该控件定义供用户选择的选项。ItemsControl->MenuBase->MultiSelector
MenuItemsControl表示一个 Windows 菜单控件。ItemsControl->MenuBase->Menu
MultiSelectorItemsControl为允许选择多项的控件提供抽象类。ItemsControl->Selector
SelectorItemsControl表示允许用户从其子元素中选择项的控件。ItemsControl->Selector
TabControlItemsControl表示包含多个项的控件,这些项共享屏幕上的同一空间。ItemsControl->Selector->TabControl
TreeViewItemsControl表示一个控件,该控件在树结构(其中的项可以展开和折叠)中显示分层数据。ItemsControl->TreeView
带标题的条目控件MenuItemHeaderedItemsControl表示 Menu 内某个可选择的项。HeaderedItemsControl->MenuItem内容为Items、ItemsSource、Header
ToolBarHeaderedItemsControl为一组命令或控件提供容器。HeaderedItemsControl->ToolBar
TreeViewItemHeaderedItemsControl在 TreeView 控件中实现可选择的项。HeaderedItemsControl->TreeViewItem
其他CalendarControl允许用户使用可视的日历显示来选择日期Control->Calendar 
ControlControl用户界面 (UI) 元素的基类,这些元素使用 ControlTemplate 来定义其外观。Control
DatePickerControl表示一个允许用户选择日期的控件Control->DatePicker
DocumentViewerControl表示一个文档查看控件,该控件可以承载分页的 FixedDocument 内容,例如 XpsDocument。Control->DocumentViewerBase->DocumentViewer
DocumentViewerBaseControl提供用于显示固定内容或流动内容(分别由 FixedDocument 或 FlowDocument 表示)的查看器的基类。Control->DocumentViewerBase
FlowDocumentReaderControl提供一种查看流内容的控件,该控件内置了对多种查看模式的支持。Control->FlowDocumentReader
FlowDocumentScrollViewerControl提供一种控件,该控件以连续滚动模式查看流内容。Control->FlowDocumentScrollViewer
GridSplitterControl表示重新分布 Grid 控件的列间距或行间距的控件。Control->Thumb->GridSplitter
KeyTipControlControl表示在 KeyTip 内部使用的控件。Control->KeyTipControl
ProgressBarControl指示操作进度。Control->RangeBase->ProgressBar
RangeBaseControl表示具有特定范围内值的元素。Control->RangeBase
RichTextBoxControl表示对 FlowDocument 对象进行操作的丰富编辑控件。Control->TextBoxBase->RichTextBox
SeparatorControl用于分隔项控件中各个项的控件。Control->Separator
SliderControl表示一个控件,该控件可让用户通过沿Thumb移动 Track 控件从一个值范围中进行选择。Control->RangeBase->Slider
StickyNoteControlControl表示一个控件,该控件允许用户在文档中附加键入的文本或手写的批注。Control->StickyNoteControl
ThumbControl表示可以由用户拖动的控件。Control->Thumb
TextBoxBaseControl为文本编辑控件提供功能的抽象基类,包括 TextBox 和 RichTextBox。Control->TextBoxBase
TextBoxControl显示或编辑无格式文本Control->TextBoxBase->TextBox
AccessText FrameworkElement热键字符FrameworkElement->AccessText  
AdornedElementPlaceholderFrameworkElement指定修饰控件相对于 ControlTemplate 中的其他元素所放置的位置FrameworkElement->AdornedElementPlaceholder 
ColumnDefinitionFrameworkElement定义将应用于 Grid 元素的特定于列的属性。FrameworkElement->DefinitionBase>ColumnDefinition 
ContentPresenterFrameworkElement显示 ContentControl 的内容。FrameworkElement->ContentPresenter 
ControlTemplateFrameworkElement指定 Control 的可在其多个实例之间共享的可视结构和行为方面。FrameworkElement->ControlTemplate 
DecoratorFrameworkElement提供在单个子元素(如 Border 或 Viewbox)上或周围应用效果的元素的基类。FrameworkElement->Decorator起UI装饰作用,内容属性为Child,只能由单一元素充当内容
ButtonChromeFrameworkElement为 Button 元素创建特定于主题的外观。FrameworkElement->Decorator->ButtonChrome
ClassicBorderDecoratorFrameworkElement创建 Decorator 类型的特定于主题的外观,以与传统型主题一起使用。FrameworkElement->Decorator->ClassicBorderDecorator
ListBoxChromeFrameworkElement为 ListBox 元素创建特定于主题的外观。FrameworkElement->Decorator->ListBoxChrome
SystemDropShadowChromeFrameworkElement创建投影效果的特定于主题的外观。FrameworkElement->Decorator->SystemDropShadowChrome
BorderFrameworkElement在另一个元素四周绘制边框和/或背景FrameworkElement->Decorator->Border
InkPresenterFrameworkElement在图面上呈现墨迹。FrameworkElement->Decorator->InkPresenter
BulletDecoratorFrameworkElement表示一个布局控件,该控件将项目符号与另一个可视对象对齐。FrameworkElement->Decorator->BulletDecorator
ViewboxFrameworkElement定义一个内容修饰器,以便拉伸或缩放单一子项使其填满可用的控件。FrameworkElement->Decorator->Viewbox
AdornerFrameworkElement表示修饰 UIElement 的 FrameworkElement 的抽象类。FrameworkElement->Decorator->Adorner
AdornerLayerFrameworkElement表示用于呈现装饰器的图面。FrameworkElement->Decorator->AdornerLayer
AnchoredBlockFrameworkElement为 Inline 元素提供基类的抽象类,这些元素用于将 Block 元素锚定到流内容。FrameworkElement->Decorator->AnchoredBlock
AdornerDecoratorFrameworkElement为可视化树中的子元素提供 AdornerLayer。FrameworkElement->Decorator->AdornerDecorator
ImageFrameworkElement显示图像的控件。FrameworkElement->Image 
InkCanvasFrameworkElement定义接收和显示墨迹笔划的区域。FrameworkElement->InkCanvas 
ItemsPanelTemplateFrameworkElement指定 ItemsPresenter 为 ItemsControl 的项的布局创建的面板。FrameworkTemplate->ItemsPanelTemplate 
ItemsPresenterFrameworkElement在项控件的模板中使用,用于指定要将 ItemsPanel 定义的 ItemsControl 添加到控件的可视化树中的什么位置。FrameworkElement->ItemsPresenter 
MediaElementFrameworkElement表示包含音频和/或视频的控件。FrameworkElement->MediaElement 
PageFrameworkElement封装一页可由 Windows Internet Explorer、NavigationWindow 和 Frame 导航到和承载的内容。FrameworkElement->Page 
RowDefinitionFrameworkElement定义将应用于 Grid 元素的特定于行的属性。FrameworkElement->DefinitionBase>RowDefinition 
ScrollContentPresenterFrameworkElement显示 ScrollViewer 控件的内容。FrameworkElement->ContentPresenter->ScrollContentPresenter 
TextBlockFrameworkElement提供一个轻型控件,用于显示少量流内容。FrameworkElement->TextBlock 
Viewport3DFrameworkElement呈现 Viewport3D 元素的 2-D 布局范围内包含的 3-D 内容。FrameworkElement->Viewport3D 
WebBrowserFrameworkElement承载 HTML 文档并在其之间导航。 启用 WPF 托管代码和 HTML 脚本之间的互操作性。FrameworkElement->HwndHost->ActiveXHost->WebBrowser 
ColumnDefinitionCollectionObject提供对 ColumnDefinition 对象的有序强类型集合的访问。Object->ColumnDefinitionCollection 
ExceptionValidationRuleObject表示用于检查绑定源属性更新过程中抛出的异常的规则。Object->ValidationRule->ExceptionValidationRule
InkPresenterObject在图面上呈现墨迹。Object->DispatcherObject->CollectionView->ItemCollection
ItemCollectionObject包含构成 ItemsControl 的内容的项的列表。Object->DispatcherObject->CollectionView->ItemCollection
NotifyDataErrorValidationRuleObject表示一个规则,该规则检查由源对象的 INotifyDataErrorInfo 实现所引发的错误。Object->ValidationRule->NotifyDataErrorValidationRule
PrintDialogObject调用标准的 Microsoft Windows 打印对话框,此对话框可根据用户输入配置 PrintTicket 和 PrintQueue,然后打印文档。Object->PrintDialog
RowDefinitionCollectionObject提供对 RowDefinition 对象的有序强类型集合的访问。Object->RowDefinitionCollection
SpellCheckObject为文本编辑控件(如 TextBox 和 RichTextBox)提供实时拼写检查功能。Object->SpellCheck
SoundPlayerActionObject表示用于播放 .wav 文件的轻量音频播放 TriggerAction。Object->DependencyObject->TriggerAction->SoundPlayerAction
ValidationObject提供支持数据验证的方法和附加属性。Object->Validation
ValidationResultObject表示从 ValidationRule.Validate(Object, CultureInfo) 返回的结果 方法指示选中值是否通过 ValidationRule。Object->ValidationResult
ValidationRuleObject提供创建自定义规则的一个方式,旨在检查用户输入的有效性。ContentControl->BaseButton->Button
ViewBaseObject表示定义 ListView 控件中数据外观的视图的基类。Object->DependencyObject->ViewBase
ShapeEllipseShape绘制椭圆形。Shape->Ellipse
FrameworkElement->
Shape                          用于2D图形绘制,使用Fill设置填充、Stroke设置边线
LineShape在两个点之间绘制直线。Shape->Line
PathShape绘制一系列相互连接的直线和曲线。Shape->Path
PolygonShape绘制多边形,它是由一系列相互连接的线条构成的闭合形状。Shape->Polygon
PolylineShape绘制一系列相互连接的直线。Shape->Polyline
RectangleShape绘制矩形。Shape->Rectangle
ShapeShape为 Ellipse、Polygon 和 Rectangle 之类的形状元素提供基类。Shape->Shape

 

UI元素类型
名称注释
ContentControl单一内容
HeaderedContentControl带标题的单一内容
ItemsControl以条目集合为内容
HeaderedContentControl带标题的以条目集合为内容
Decorator控件装饰元素
Panel面板类元素
Adorner 文字点缀元素
Flow Text流式文本元素
TextBox文本输入框
TextBlock静态文字
Shape图形元素

 

ItemsControl名称对应的Item Containier
ComboBoxComboBoxItem
ContextMenuMenuItem
ListBoxListBoxItem
ListViewListViewItem
MenuMenuItem
StatusBarStatusBarItem
TabControlTabItem
TreeViewTreeViewItem

 


二)UI

一般是把窗体或页面的左上角作为坐标系的原点。


2.1)UI父类

Object->DispatcherObject->DependencyObject->Visual->UIElement->FrameworkElement->Control


2.1.1 Object类

所有类的基类,主要有Equals、GetHashCode、GetType、MemberwiseClone、ReferenceEquals、ToString方法。

public class Object
{
    //构造函数
    public Object(){}

    //析构函数
    ~Object() {}
    
    // 确定指定对象是否等于当前对象。    
    public virtual bool Equals(Object obj){}
    
    //确定指定的对象实例是否被视为相等。
    public static bool Equals(Object objA, Object objB){}
        
    //作为默认哈希函数。
    public virtual int GetHashCode(){}
        
    //获取当前实例的 Type。
    public extern Type GetType(){}
    
   //创建当前 Object 的浅表副本。
    protected extern Object MemberwiseClone();               

     //确定指定的 Object 实例是否是相同的实例。
    public static bool ReferenceEquals (Object objA, Object objB) {}

    //确定指定的对象实例是否被视为相等。
    public virtual String ToString(){} 
}

2.1.2 DispatcherObject类

派生自Object类,表示与 Dispatcher 关联的对象。Dispatcher:提供用于管理线程工作项队列的服务。

只有创建Dispatcher 的线程才能直接访问DispatcherObject 。 若要从 DispatcherObject 创建的线程以外的线程访问 DispatcherObject ,请调用关联Dispatcher上的DispatcherObject 的InvokeBeginInvoke 。

需要加强线程安全性的DispatcherObject子类可以通过在所有公共方法上调用VerifyAccess来实现。 这样可以保证调用线程是在其上创建DispatcherObject的线程。

所有构造函数都受到保护,DispatcherObject不能单独实例化。

从DispatcherObject派生的对象具有线程相似性。

从派生的对象在 Freezable 被冻结时是自由线程的。 有关详细信息,请参阅 Freezable 对象概述

//派生自的对象 DispatcherObject 具有线程关联。
public abstract class DispatcherObject
    {
        //获取与此 Dispatcher 关联的 DispatcherObject。
        public Dispatcher Dispatcher => _dispatcher;

        //确定调用线程是否可以访问此 DispatcherObject。
        public bool CheckAccess(){}
       
        //强制调用线程具有此 DispatcherObject 的访问权限。
        public void VerifyAccess(){}        
    }

2.1.3 DependencyObject类

表示参与依赖属性系统的对象。所有依赖属性都派生自次类。

DependencyObject类在其多个派生类上启用 Windows Presentation Foundation (WPF) 属性系统服务。

属性系统的主要功能是计算属性值,并提供有关已更改值的系统通知。 参与属性系统的另一个关键类是DependencyProperty。 DependencyProperty允许将依赖项属性注册到属性系统中,并提供有关每个依赖项属性的标识和信息,而DependencyObject作为基类使对象可以使用依赖项属性。

DependencyObject 服务和特征包括:

  • 依赖属性承载支持。 通过调用 Register 方法,并将该方法的返回值存储为类中的公共静态字段,来注册依赖属性。
  • 附加属性托管支持。 可以通过调用方法来注册附加属性 RegisterAttached ,并将该方法的返回值存储为类中的公共静态只读字段。 (还有其他成员要求;请注意,这表示附加属性的 WPF 特定实现。 有关详细信息,请参阅 附加属性概述。然后可以在派生自的任何类上设置附加属性 DependencyObject ) 。
  • 获取、设置和清除中存在的任何依赖项属性值的实用工具方法 DependencyObject 。
  • 元数据、强制值支持、属性更改通知和替代依赖属性或附加属性的回调 此外, DependencyObject 类还有助于依赖项属性的每个所有者的属性元数据。
  • 派生自、或的类的公共 ContentElement 基类 Freezable Visual 。 (UIElement ,另一个基元素类具有包含的类层次结构 Visual 。 )
public class DependencyObject : DispatcherObject
{
        //获取 DependencyObjectType 包装此实例的 CLR 类型的。
        public DependencyObjectType DependencyObjectType

        //获取一个值,该值指示此实例当前是否为密封的(只读)。       
        public bool IsSealed => DO_Sealed;    

        //确定提供的 DependencyObject 是否等效于当前 DependencyObject。
        public sealed override bool Equals(object obj){}

        //获取此 DependencyObject 的哈希代码。
        public sealed override int GetHashCode(){}   

        //创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。
        public LocalValueEnumerator GetLocalValueEnumerator ();

        //对 DependencyObject 的此实例返回依赖属性的当前有效值。
        public object GetValue(DependencyProperty dp){}  

        //设置依赖属性的本地值,该值由其依赖属性标识符指定。
        public void SetValue(DependencyProperty dp, object value){}

        //设置依赖属性的值而不更改其值源。    
        public void SetCurrentValue(DependencyProperty dp, object value){}

        //设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。       
        public void SetValue(DependencyPropertyKey key, object value){}     

        //清除属性的本地值。 要清除的属性由 DependencyProperty 标识符指定。
        public void ClearValue(DependencyProperty dp){}

        //清除只读属性的本地值。 要清除的属性由 DependencyPropertyKey 指定。 
        public void ClearValue(DependencyPropertyKey key){}

        //对指定依赖属性的值进行强制。 通过对调用方 DependencyObject 上存在的依赖属性的属性元数据中所指定的任何 CoerceValueCallback 函数进行调用来完成此操作。
        public void CoerceValue(DependencyProperty dp){}  

        //重新评估指定依赖属性的有效值 
        public void InvalidateProperty(DependencyProperty dp){} 

        //如果存在,则返回依赖属性的本地值。
        public object ReadLocalValue(DependencyProperty dp){}    

        //返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。
        protected internal virtual bool ShouldSerializeProperty(DependencyProperty dp);

        //每当更新此 DependencyObject 的任何依赖属性的有效值时调用。 更改的特定依赖属性将在事件数据中报告。
        protected virtual void OnPropertyChanged (DependencyPropertyChangedEventArgs e);
}



2.1.4 Visual类

为 WPF 中的呈现提供支持,其中包括命中测试、坐标转换和边界框计算。

Visual类是 FrameworkElement 类的基类 。 还用作在WPF中编写新控件的入口点,并且在许多方面都可以被视为Win32应用程序模型中的窗口句柄(HWND)的等效项。

Visual对象是WPF的核心对象,其主要作用是提供渲染支持。 用户界面控件(例如Button和TextBox)从Visual类派生,并使用Visual定义的属性来持久保存其呈现数据。 Visual对象为以下内容提供支持:

  • 输出显示:呈现视觉对象的持久、序列化的绘图内容。
  • 转换:针对视觉对象执行转换。
  • 剪裁:为视觉对象提供剪裁区域支持。
  • 命中测试:确定指定的坐标 (点) 还是几何图形是否包含在视觉对象的边界内。
  • 边框计算:确定视觉对象的边框。

从结构上讲,Visual对象不支持与其他应用程序开发要求/ WPF功能(与它们的呈现不直接相关)的支持,例如:

  • 事件处理
  • Layout(布局)
  • 样式
  • 数据绑定
  • 全球化

Visual 作为可从中派生更多类的公共抽象类提供。 下图显示了在 WPF 体系结构中定义的现有视觉对象的层次结构。

从 Visual 对象派生的类的示意图
视觉对象类层次结构

在某些情况下,在派生类中,定义为受保护的成员 Visual 将公开为更易于访问的成员,具有类似的名称 UIElement 。

有关详细信息,请参阅 WPF 图形呈现概述

Visual具有有限的级别数。 在 .NET Framework 的以前版本中,此最大深度为255。 对于在可视化树中具有多个级别的某些布局而言,此限制不够用。

在 .NET Framework 4 中,的最大深度 Visual 为2047,这可以实现更多的可视化树。 在大多数应用程序中,堆栈空间不足,无法遍历太多级别,结果在 StackOverflowException 布局期间是。 对于默认堆栈大小,如果树深度大约为800(相当于大约190个嵌套对象),则通常会引发此异常 TreeViewItem 。

如果你的应用程序引发此异常,并且你需要具有更深入的可视化树,则可以增加应用程序的堆栈大小。 可以通过在编译时使用/STACK 选项或使用 EDITBIN 实用工具来增加堆栈的大小。 增大堆栈大小可能会影响应用程序的性能。 有关详细信息,请参阅 Stack 分配 和 EDITBIN 选项

public abstract class Visual : DependencyObject, DUCE.IResource
{
    //###################属性###################

    //定义位图效果。
    public System.Windows.Media.Effects.BitmapEffect VisualBitmapEffect { protected internal get; protected set; }

    //注意:此 API 现已过时。 未过时的替代项为 Effect
    public System.Windows.Media.Effects.BitmapEffectInput VisualBitmapEffectInput { protected internal get; protected set; }

    //指定用于缩放位图图像的算法。
    public BitmapScalingMode VisualBitmapScalingMode {}

    //用于容纳 Visual 的缓存表示形式。
    public CacheMode VisualCacheMode {}

    //获取 Visual 的子元素数量。
    protected virtual int VisualChildrenCount {}

    //获取或设置 ClearTypeHint,它确定在 Visual 中呈现 ClearType 的方式。
    protected internal ClearTypeHint VisualClearTypeHint {}

    //获取或设置 Visual 的剪辑区域作为 Geometry 值。
    public Geometry VisualClip {}

    //获取或设置 Visual 的边缘模式作为 EdgeMode 值。(确定非文本绘图基元的边缘的呈现方式)
    public EdgeMode VisualEdgeMode {}

    //获取或设置要应用于 Visual 的位图效果(获取或设置要应用于 Visual 的位图效果。)
    public Effect VisualEffect {}

    //获取或设置可视对象的偏移量值。
    public Vector VisualOffset {}

    //获取或设置 Visual 的不透明度。
    public double VisualOpacity {}

    //获取或设置 Brush(定义用于绘制图形对象的对象。) 值,该值表示 Visual 的不透明蒙板。
    public Brush VisualOpacityMask {}

    //获取可视对象的可视化树父级。
    protected DependencyObject VisualParent {}

    //获取或设置 Visual 的剪辑的可滚动区域
    public Rect? VisualScrollableAreaClip {}

    //获取或设置 Visual 的 TextHintingMode。(定义静态文本或动画文本的呈现行为。)
    protected internal TextHintingMode VisualTextHintingMode {}

    //获取或设置 Visual 的 TextRenderingMode。(为文本定义支持的呈现模式。)
    protected internal TextRenderingMode VisualTextRenderingMode {}

    //获取或设置 Transform 的 Visual 值。(可视对象的转换值。)
    public Transform VisualTransform {}

    //获取或设置 x 坐标(垂直)准线集合
    public DoubleCollection VisualXSnappingGuidelines {}

    //获取或设置 Y 坐标(水平)准线集合。
    public DoubleCollection VisualYSnappingGuidelines {}


    //###################方法###################

    //定义两个可视对象之间的父子关系。
    protected void AddVisualChild ();

    //返回两个可视对象的公共上级。
    public DependencyObject FindCommonVisualAncestor (DependencyObject otherVisual);

    //返回父级 Visual 中的指定 VisualCollection。
    protected virtual Visual GetVisualChild (int index);

    //确定点或几何图形值是否在可视对象的边界内。
    protected virtual GeometryHitTestResult HitTestCore (GeometryHitTestParameters hitTestParameters);
    protected virtual HitTestResult HitTestCore (PointHitTestParameters hitTestParameters);

    //确定可视对象是否为后代可视对象的上级
    public bool IsAncestorOf (DependencyObject descendant);

    //确定可视对象是否为上级可视对象的后代
    public bool IsDescendantOf (DependencyObject ancestor);

    //呈现此视图时所使用的 DPI 发生变化时进行调用。
     protected virtual void OnDpiChanged (DpiScale oldDpi, DpiScale newDpi);

    //修改可视对象的 VisualCollection 时调用。
    protected internal virtual void OnVisualChildrenChanged (DependencyObject visualAdded, DependencyObject visualRemoved);

    //当可视对象的父级更改时调用。
    protected internal virtual void OnVisualParentChanged (DependencyObject oldParent);

    //将屏幕坐标中的 Point 转换为表示 Point 的当前坐标系的 Visual。
    public Point PointFromScreen (Point point);

    //将表示 Point 的当前坐标系的 Visual 转换为屏幕坐标中的 Point。
    public Point PointToScreen (Point point);

    //移除两个可视对象之间的父子关系。
    protected void RemoveVisualChild (Visual child);

    //返回一个转换,该转换可用于将 Visual 中的坐标转换为指定的可视对象上级。
    public GeneralTransform2DTo3D TransformToAncestor (Visual3D ancestor);
    public GeneralTransform TransformToAncestor (Visual ancestor);

    //返回一个转换,该转换可用于将 Visual 中的坐标转换为指定的可视对象后代。
    public GeneralTransform TransformToDescendant (Visual descendant);

    //返回一个转换,该转换可用于将 Visual 中的坐标转换为指定的可视对象
    public GeneralTransform TransformToVisual (Visual visual);

}

2.1.5 UIElement 类

UIElement 是 WPF 核心级实现的基类,这些实现是在 Windows Presentation Foundation (WPF) 元素和基本表示特性上生成的。

UIElement 提供元素布局特征的起点,还公开派生类可以重写的虚拟方法,这可能会影响元素及其子元素的布局呈现行为。

通常,类中还定义了元素的大部分输入和焦点行为 UIElement 。 这包括键盘、鼠标和触笔输入的事件以及相关的状态属性。 其中的许多事件都是路由事件,许多输入相关事件都具有冒泡路由版本以及事件的隧道版本。 这些配对事件通常是控制作者最感兴趣的事件。

UIElement 还包括与 WPF 事件模型相关的 API,包括可以引发源自元素实例的指定路由事件的方法。

在体系结构方面,UIElement可以大致等同于Win32编程中的窗口句柄或动态HTML(DHTML)编程中的Element。 UIElement是WPF核心级别的基础元素。

UIElement具有由类专门定义的以下功能 UIElement :

  • 可作为 (派生自的子元素呈现 UIElement Visual)
  • 包含用于 UIElement 在布局系统进行解释时调整 (的可能子元素的大小和位置的逻辑)
  • 可以响应用户输入 (包括通过其事件路由处理来控制输入发送到的位置,或路由命令)
  • 可以引发通过逻辑元素树传送路由的路由事件
  • 支持动画系统的某些方面

FrameworkElement 是在上生成的 WPF 框架级别实现类 UIElement ,并添加了与 WPF 框架级别的特定交互。 FrameworkElement 添加并定义以下功能:

  • 其他框架特定的布局特征
  • 支持更丰富的元数据报告属性
  • 某些输入基类的特定于类的实现及其附加属性或附加事件
  • 风格支持
  • 更多动画支持

另一个相关的类是 ContentElement 。 ContentElement类实现了许多与 UIElement 相同的成员; 这两个类别之间的差异与它们在整体内容模型中的预期位置有关。 UIElement派生类通常定义一个相对严格的内容模型,这意味着在标记中哪些元素可能是子元素存在限制。UIElement中可能有一些限制较少的子内容的容量,但是该容量通常集中在指定的内容属性中。 ContentElement派生类通常不会对内容进行限制,以支持流格式文档等方案。

Visibility 状态会影响该元素的所有输入处理。 不可见的元素不参与命中测试,也不会接收到输入事件,即使鼠标位于元素显示的边界处

//字段
public class UIElement : Visual, IAnimatable, IInputElement
    {
        //获取或设置一个值,该值指示此元素能否用作拖放操作的目标。
        public static readonly System.Windows.DependencyProperty AllowDropProperty;

        //获取一个值,该值指示在此元素上是否至少捕获了一次触摸。
        public static readonly System.Windows.DependencyProperty AreAnyTouchesCapturedProperty;

        //获取一个值,该值指示在此元素或其可视化树中的任何子元素上是否至少捕获了一次触摸。
        public static readonly System.Windows.DependencyProperty AreAnyTouchesCapturedWithinProperty;

        //获取一个值,该值指示在此元素上是否至少按下了一次触摸设备。
        public static readonly System.Windows.DependencyProperty AreAnyTouchesDirectlyOverProperty;

        //获取一个值,该值指示在此元素或其可视化树中的任何子元素上是否至少按下了一次触摸设备。
        public static readonly System.Windows.DependencyProperty AreAnyTouchesOverProperty;

        //获取或设置位图效果的输入源,该效果将直接应用到此元素所呈现的内容。
        public static readonly System.Windows.DependencyProperty BitmapEffectInputProperty;

        //获取或设置一个位图效果,该效果将直接应用到此元素所呈现的内容。
        public static readonly System.Windows.DependencyProperty BitmapEffectProperty;

        //获取或设置 UIElement 的缓存表示形式
        public static readonly System.Windows.DependencyProperty CacheModeProperty;

        //获取或设置用于定义元素内容轮廓的几何图形。
        public static readonly System.Windows.DependencyProperty ClipProperty;

        //获取或设置一个值,该值指示是否剪切此元素的内容(或来自此元素的子元素的内容)使其适合包含元素的大小。
        public static readonly System.Windows.DependencyProperty ClipToBoundsProperty;

        //在输入系统报告出现以此元素为拖动目标的基础拖动事件时发生。
        public static readonly System.Windows.RoutedEvent DragEnterEvent;

        //在输入系统报告出现以此元素为拖动起点的基础拖动事件时发生
        public static readonly System.Windows.RoutedEvent DragLeaveEvent;

        //在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。
        public static readonly System.Windows.RoutedEvent DragOverEvent;

        //在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。
        public static readonly System.Windows.RoutedEvent DropEvent;

        //获取或设置要应用于 UIElement 的位图效果。
        public static readonly System.Windows.DependencyProperty EffectProperty;

        //获取或设置一个值,该值指示元素能否得到焦点
        public static readonly System.Windows.DependencyProperty FocusableProperty;

        //在输入系统报告出现涉及此元素的基础拖放操作时发生。
        public static readonly System.Windows.RoutedEvent GiveFeedbackEvent;

        //在此元素获得逻辑焦点时发生。
        public static readonly System.Windows.RoutedEvent GotFocusEvent;

        //在此元素聚焦于键盘时发生。
        public static readonly System.Windows.RoutedEvent GotKeyboardFocusEvent;

        //在此元素捕获鼠标时发生。
        public static readonly System.Windows.RoutedEvent GotMouseCaptureEvent;

        //在此元素捕获触笔时发生。
        public static readonly System.Windows.RoutedEvent GotStylusCaptureEvent;

        //在此元素上捕获触摸屏输入时发生。
        public static readonly System.Windows.RoutedEvent GotTouchCaptureEvent;

        //在此元素的 IsEnabled 属性值更改时发生。
        public static readonly System.Windows.DependencyProperty IsEnabledProperty;

        //获取一个值,该值确定此元素是否具有逻辑焦点。
        public static readonly System.Windows.DependencyProperty IsFocusedProperty;

        //获取或设置一个值,该值声明是否可以返回此元素作为其呈现内容的某些部分的点击测试结果。
        public static readonly System.Windows.DependencyProperty IsHitTestVisibleProperty;

        //获取一个值,该值表示该元素是否具有键盘焦点。
        public static readonly System.Windows.DependencyProperty IsKeyboardFocusedProperty;

        //获取一个值,该值指示键盘焦点是否位于元素或其可视化树子元素内的任意位置。
        public static readonly System.Windows.DependencyProperty IsKeyboardFocusWithinProperty;

        //获取或设置一个值,该值指示是否对此 UIElement 启用操作事件。
        public static readonly System.Windows.DependencyProperty IsManipulationEnabledProperty;

        //获取一个值,该值指示此元素是否捕获了鼠标。
        public static readonly System.Windows.DependencyProperty IsMouseCapturedProperty;

        //获取一个值,该值确定鼠标捕获是由此元素还是其可视化树中的子元素持有。
        public static readonly System.Windows.DependencyProperty IsMouseCaptureWithinProperty;

        //获取一个值,该值指示在考虑元素组合的情况下,鼠标指针的位置是否与命中测试结果相对应。
        public static readonly System.Windows.DependencyProperty IsMouseDirectlyOverProperty;

        //获取一个值,该值指示鼠标指针是否位于此元素(包括可视化树中的子元素)的上方。
        public static readonly System.Windows.DependencyProperty IsMouseOverProperty;

        //获取一个值,该值表示此元素是否捕获了触笔。
        public static readonly System.Windows.DependencyProperty IsStylusCapturedProperty;

        //获取一个值,该值确定触笔捕获是由此元素还是由元素边界内的元素及其可视化树持有。
        public static readonly System.Windows.DependencyProperty IsStylusCaptureWithinProperty;

        //获取一个值,该值指示在考虑元素组合的情况下,触笔的位置是否与命中测试结果相对应。
        public static readonly System.Windows.DependencyProperty IsStylusDirectlyOverProperty;

        //获取一个值,该值指示触笔指针是否位于此元素(包括可视化子元素)的上方。
        public static readonly System.Windows.DependencyProperty IsStylusOverProperty;

        //获取一个值,该值指示此元素在用户界面中是否可见 (UI) 。
        public static readonly System.Windows.DependencyProperty IsVisibleProperty;

        //当焦点在该元素上时按下某个键后发生。
        public static readonly System.Windows.RoutedEvent KeyDownEvent;

        //当焦点在该元素上时松开某个键后发生。
        public static readonly System.Windows.RoutedEvent KeyUpEvent;

        //在此元素丢失逻辑焦点时发生。
        public static readonly System.Windows.RoutedEvent LostFocusEvent;

        //在键盘焦点不再位于此元素上时发生。
        public static readonly System.Windows.RoutedEvent LostKeyboardFocusEvent;

        //在此元素丢失鼠标捕获时发生。
        public static readonly System.Windows.RoutedEvent LostMouseCaptureEvent;

        //在此元素丢失触笔捕获时发生。
        public static readonly System.Windows.RoutedEvent LostStylusCaptureEvent;

        //在此元素失去触摸屏输入捕获时发生。
        public static readonly System.Windows.RoutedEvent LostTouchCaptureEvent;

        //当操作遇到边界时发生。
        public static readonly System.Windows.RoutedEvent ManipulationBoundaryFeedbackEvent;

        //对于 UIElement 对象的操作和延时完毕时发生
        public static readonly System.Windows.RoutedEvent ManipulationCompletedEvent;

        //当输入设备在操作期间更改位置时发生。
        public static readonly System.Windows.RoutedEvent ManipulationDeltaEvent;

        //当输入设备在操作期间与 UIElement 对象失去联系且延时开始时发生。
        public static readonly System.Windows.RoutedEvent ManipulationInertiaStartingEvent;

        //当输入设备对 UIElement 对象开始操作时发生。
        public static readonly System.Windows.RoutedEvent ManipulationStartedEvent;

        //在首次创建操作处理器时发生。
        public static readonly System.Windows.RoutedEvent ManipulationStartingEvent;

        //在指针位于此元素上并且按下任意鼠标按钮时发生。
        public static readonly System.Windows.RoutedEvent MouseDownEvent;

        //在鼠标指针进入此元素的边界时发生。
        public static readonly System.Windows.RoutedEvent MouseEnterEvent;

        //在鼠标指针离开此元素的边界时发生。
        public static readonly System.Windows.RoutedEvent MouseLeaveEvent;

        //在鼠标指针位于此元素上并且按下鼠标左键时发生。
        public static readonly System.Windows.RoutedEvent MouseLeftButtonDownEvent;

        //在鼠标指针位于此元素上并且松开鼠标左键时发生。
        public static readonly System.Windows.RoutedEvent MouseLeftButtonUpEvent;

        //在鼠标指针位于此元素上并且移动鼠标指针时发生。
        public static readonly System.Windows.RoutedEvent MouseMoveEvent;

        //在鼠标指针位于此元素上并且按下鼠标右键时发生。
        public static readonly System.Windows.RoutedEvent MouseRightButtonDownEvent;

        //在鼠标指针位于此元素上并且松开鼠标右键时发生。
        public static readonly System.Windows.RoutedEvent MouseRightButtonUpEvent;

        //在鼠标指针位于此元素上并且松开任意鼠标按钮时发生。
        public static readonly System.Windows.RoutedEvent MouseUpEvent;

        //在鼠标指针位于此元素上并且用户滚动鼠标滚轮时发生。
        public static readonly System.Windows.RoutedEvent MouseWheelEvent;

        //获取或设置一个作为 Brush 实现的不透明蒙板,该蒙板可应用到此元素所呈现内容的任何 Alpha 通道蒙板。
        public static readonly System.Windows.DependencyProperty OpacityMaskProperty;

        //获取或设置在 UIElement 用户界面 (UI) 中呈现时应用于整个的不透明度因子。
        public static readonly System.Windows.DependencyProperty OpacityProperty;

        //在输入系统报告出现以此元素为拖动目标的基础拖动事件时发生。
        public static readonly System.Windows.RoutedEvent PreviewDragEnterEvent;

        //在输入系统报告出现以此元素为拖动起点的基础拖动事件时发生。
        public static readonly System.Windows.RoutedEvent PreviewDragLeaveEvent;

        //在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。
        public static readonly System.Windows.RoutedEvent PreviewDragOverEvent;

        //在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。
        public static readonly System.Windows.RoutedEvent PreviewDropEvent;

        //在开始拖放操作时发生。
        public static readonly System.Windows.RoutedEvent PreviewGiveFeedbackEvent;

        //在此元素聚焦于键盘时发生。
        public static readonly System.Windows.RoutedEvent PreviewGotKeyboardFocusEvent;

        //当焦点在该元素上时按下某个键后发生。
        public static readonly System.Windows.RoutedEvent PreviewKeyDownEvent;

        //当焦点在该元素上时松开某个键后发生。
        public static readonly System.Windows.RoutedEvent PreviewKeyUpEvent;

        //在此元素不再聚焦于键盘时发生。
        public static readonly System.Windows.RoutedEvent PreviewLostKeyboardFocusEvent;

        //在指针位于此元素上并且按下任意鼠标按钮时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseDownEvent;

        //在鼠标指针位于此元素上并且按下鼠标左键时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseLeftButtonDownEvent;

        //在鼠标指针位于此元素上并且松开鼠标左键时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseLeftButtonUpEvent;

        //在鼠标指针位于此元素上并且移动鼠标指针时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseMoveEvent;

        //在鼠标指针位于此元素上并且按下鼠标右键时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseRightButtonDownEvent;

        //在鼠标指针位于此元素上并且松开鼠标右键时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseRightButtonUpEvent;

        //在鼠标指针位于此元素上并且松开任意鼠标按钮时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseUpEvent;

        //在鼠标指针位于此元素上并且用户滚动鼠标滚轮时发生。
        public static readonly System.Windows.RoutedEvent PreviewMouseWheelEvent;

        //在拖放操作期间键盘或鼠标按钮的状态改变时发生。
        public static readonly System.Windows.RoutedEvent PreviewQueryContinueDragEvent;

        //在指针位于此元素上并且按下触笔按钮时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusButtonDownEvent;

        //在指针位于此元素上并且松开触笔按钮时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusButtonUpEvent;

        //当触笔位于元素上且触及数字化器时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusDownEvent;

        //在触笔掠过元素但并未实际接触数字化器时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusInAirMoveEvent;

        //在触笔位于此元素上并且触笔与数字化器之间的距离近到足以检测到触笔时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusInRangeEvent;

        //在触笔位于元素上并且移动触笔时发生。 数字化器在检测触笔时,触笔必须处于移动状态才会引发此事件,否则将改为引发 PreviewStylusInAirMove。
        public static readonly System.Windows.RoutedEvent PreviewStylusMoveEvent;

        //在触笔与数字化仪之间的距离太远以致无法检测到触笔时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusOutOfRangeEvent;

        //在用户采用某一种触笔笔势时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusSystemGestureEvent;

        //当触笔位于此元素上并且用户将触笔抬离数字化器时发生。
        public static readonly System.Windows.RoutedEvent PreviewStylusUpEvent;

        //在此元素以设备无关模式获取文本时发生。
        public static readonly System.Windows.RoutedEvent PreviewTextInputEvent;

        //当悬停在此元素上方的手指触摸屏幕时发生。
        public static readonly System.Windows.RoutedEvent PreviewTouchDownEvent;

        //当悬停在此元素上方的手指在屏幕上移动时发生。
        public static readonly System.Windows.RoutedEvent PreviewTouchMoveEvent;

        //当悬停在此元素上方的手指从屏幕上移开时发生。
        public static readonly System.Windows.RoutedEvent PreviewTouchUpEvent;

        //在拖放操作期间键盘或鼠标按钮的状态改变时发生。
        public static readonly System.Windows.RoutedEvent QueryContinueDragEvent;

        //当请求显示光标时发生。 每次鼠标指针移至新位置时都会在一个元素上引发此事件,这意味着光标对象可能需要根据其新位置进行更改。
        public static readonly System.Windows.RoutedEvent QueryCursorEvent;

        //获取或设置由 RenderTransform 声明的任何可能呈现转换的中心点,相对于元素的边界。
        public static readonly System.Windows.DependencyProperty RenderTransformOriginProperty;

        //获取或设置影响此元素的呈现位置的转换信息。
        public static readonly System.Windows.DependencyProperty RenderTransformProperty;

        //获取或设置一个值,该值确定在呈现过程中,此元素的呈现是否应使用特定于设备的像素设置。
        public static readonly System.Windows.DependencyProperty SnapsToDevicePixelsProperty;

        //在指针位于此元素上并且按下触笔按钮时发生。
        public static readonly System.Windows.RoutedEvent StylusButtonDownEvent;

        //在指针位于此元素上并且松开触笔按钮时发生。
        public static readonly System.Windows.RoutedEvent StylusButtonUpEvent;

        //在触笔位于此元素上且同时触及数字化器时发生。
        public static readonly System.Windows.RoutedEvent StylusDownEvent;

        //在触笔进入此元素的边界时发生。
        public static readonly System.Windows.RoutedEvent StylusEnterEvent;

        //在触笔掠过元素但并未实际接触数字化器时发生。
        public static readonly System.Windows.RoutedEvent StylusInAirMoveEvent;

        //在触笔位于此元素上并且触笔与数字化器之间的距离近到足以检测到触笔时发生。
        public static readonly System.Windows.RoutedEvent StylusInRangeEvent;

        //在触笔离开元素的边界时发生。
        public static readonly System.Windows.RoutedEvent StylusLeaveEvent;

        //在触笔移到此元素上时发生。 触笔必须在位于数字化器上时移动,才会引发此事件。 否则将改为引发 StylusInAirMove。
        public static readonly System.Windows.RoutedEvent StylusMoveEvent;

        //在触笔位于此元素上并且触笔与数字化器之间的距离太远以致无法检测到触笔时发生。
        public static readonly System.Windows.RoutedEvent StylusOutOfRangeEvent;

        //在用户采用某一种触笔笔势时发生。
        public static readonly System.Windows.RoutedEvent StylusSystemGestureEvent;

        //当触笔位于此元素上并且用户将触笔抬离数字化器时发生。
        public static readonly System.Windows.RoutedEvent StylusUpEvent;

        //在此元素以设备无关模式获取文本时发生。
        public static readonly System.Windows.RoutedEvent TextInputEvent;

        //当悬停在此元素上方的手指触摸屏幕时发生。
        public static readonly System.Windows.RoutedEvent TouchDownEvent;

        //在触摸屏输入从此元素边界外部移动到其内部时发生。
        public static readonly System.Windows.RoutedEvent TouchEnterEvent;

        //在触摸屏输入从此元素边界内部移动到其外部时发生。
        public static readonly System.Windows.RoutedEvent TouchLeaveEvent;

        //当悬停在此元素上方的手指在屏幕上移动时发生。
        public static readonly System.Windows.RoutedEvent TouchMoveEvent;

        //当悬停在此元素上方的手指从屏幕上移开时发生。
        public static readonly System.Windows.RoutedEvent TouchUpEvent;

        //获取或设置此元素的唯一标识符(用于本地化)。
        public static readonly System.Windows.DependencyProperty UidProperty;

        //获取或设置用户界面(UI) 此元素的可见性。
        public static readonly System.Windows.DependencyProperty VisibilityProperty;
    }
 //属性
public class UIElement : Visual, IAnimatable, IInputElement
    {
        //获取或设置一个值,该值指示此元素能否用作拖放操作的目标。 这是依赖项属性。
        public bool AllowDrop { get; set; }

        //获取一个值,该值指示在此元素上是否至少捕获了一次触摸。
        public bool AreAnyTouchesCaptured { get; }

        //获取一个值,该值指示在此元素或其可视化树中的任何子元素上是否至少捕获了一次触摸。
        public bool AreAnyTouchesCapturedWithin { get; }

        //获取一个值,该值指示在此元素上是否至少按下了一次触摸设备。
        public bool AreAnyTouchesDirectlyOver { get; }

        //获取一个值,该值指示在此元素或其可视化树中的任何子元素上是否至少按下了一次触摸设备。
        public bool AreAnyTouchesOver { get; }

        //获取或设置 UIElement 的缓存表示形式。
        public System.Windows.Media.CacheMode CacheMode { get; set; }

        //获取或设置用于定义元素内容轮廓的几何图形。 这是依赖项属性
        public System.Windows.Media.Geometry Clip { get; set; }

        //获取或设置一个值,该值指示是否剪切此元素的内容(或来自此元素的子元素的内容)使其适合包含元素的大小。 这是依赖项属性。
        public bool ClipToBounds { get; set; }

        //获取与此元素关联的 CommandBinding 对象的集合。 CommandBinding 为此元素启用命令处理,并声明命令、命令的事件和由此元素附加的处理程序之间的链接
        public System.Windows.Input.CommandBindingCollection CommandBindings { get; }

        //获取在布局流程的度量传递过程中此元素计算所得的大小。
        public System.Windows.Size DesiredSize { get; }

        //获取或设置要应用于 UIElement 的位图效果。 这是依赖项属性。
        public System.Windows.Media.Effects.Effect Effect { get; set; }

        //获取或设置一个值,该值指示元素能否得到焦点。 这是依赖项属性。
        public bool Focusable { get; set; }

        //获取一个值,该值指示此元素是否具有任何进行动画处理的属性。
        public bool HasAnimatedProperties { get; }

        //获取一个值,该值指示 UIElement 是否具有焦点。
        protected internal virtual bool HasEffectiveKeyboardFocus { get; }

        //获取与此元素关联的输入绑定的集合。
        public System.Windows.Input.InputBindingCollection InputBindings { get; }

        //获取一个值,该值指示此元素布局中的子元素的计算大小和位置是否有效。
        public bool IsArrangeValid { get; }

        //获取或设置一个值,该值指示是否在用户界面中 (UI) 启用此元素。 这是依赖项属性。
        public bool IsEnabled { get; set; }

        //获取一个值,该值成为派生类中 IsEnabled 的返回值。
        protected virtual bool IsEnabledCore { get; }

        //获取一个值,该值确定此元素是否具有逻辑焦点。 这是依赖项属性。
        public bool IsFocused { get; }

        //获取或设置一个值,该值声明是否可以返回此元素作为其呈现内容的某些部分的点击测试结果。 这是依赖项属性。
        public bool IsHitTestVisible { get; set; }

        //获取一个值,该值指示是否启用输入法系统(如输入法编辑器 (IME) )来处理此元素的输入。
        public bool IsInputMethodEnabled { get; }

        //获取一个值,该值表示该元素是否具有键盘焦点。 这是依赖项属性。
        public bool IsKeyboardFocused { get; }

        //获取一个值,该值指示键盘焦点是否位于元素或其可视化树子元素内的任意位置。 这是依赖项属性。
        public bool IsKeyboardFocusWithin { get; }

        //获取或设置一个值,该值指示是否对此 UIElement 启用操作事件。
        public bool IsManipulationEnabled { get; set; }

        //获取一个值,该值指示布局测量返回的当前大小是否有效。
        public bool IsMeasureValid { get; }

        //获取一个值,该值指示此元素是否捕获了鼠标。 这是依赖项属性。
        public bool IsMouseCaptured { get; }

        //获取一个值,该值确定鼠标捕获是由此元素还是其可视化树中的子元素持有。 这是依赖项属性。
        public bool IsMouseCaptureWithin { get; }

        //获取一个值,该值指示在考虑元素组合的情况下,鼠标指针的位置是否与命中测试结果相对应。 这是依赖项属性。
        public bool IsMouseDirectlyOver { get; }

        //获取一个值,该值指示鼠标指针是否位于此元素(包括可视化树中的子元素)的上方。 这是依赖项属性。
        public bool IsMouseOver { get; }

        //获取一个值,该值表示此元素是否捕获了触笔。 这是依赖项属性。
        public bool IsStylusCaptured { get; }

        //获取一个值,该值确定触笔捕获是由此元素还是由元素边界内的元素及其可视化树持有。 这是依赖项属性。
        public bool IsStylusCaptureWithin { get; }

        //获取一个值,该值指示在考虑元素组合的情况下,触笔的位置是否与命中测试结果相对应。 这是依赖项属性。
        public bool IsStylusDirectlyOver { get; }

        //获取一个值,该值指示触笔指针是否位于此元素(包括可视化子元素)的上方。 这是依赖项属性。
        public bool IsStylusOver { get; }

        //获取一个值,该值指示此元素在用户界面中是否可见 (UI) 。 这是依赖项属性。
        public bool IsVisible { get; }

        //获取或设置在 UIElement 用户界面 (UI) 中呈现时应用于整个的不透明度因子。 这是依赖项属性。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double Opacity { get; set; }

        //获取或设置一个作为 Brush 实现的不透明蒙板,该蒙板可应用到此元素所呈现内容的任何 Alpha 通道蒙板。 这是依赖项属性。
        public System.Windows.Media.Brush OpacityMask { get; set; }

        //获取一个唯一标识此元素的值。
        [System.Obsolete("PersistId is an obsolete property and may be removed in a future release.  The value of this property is not defined.")]
        public int PersistId { get; }

        //获取(或设置)此元素的最终呈现大小。
        public System.Windows.Size RenderSize { get; set; }

        //获取或设置影响此元素的呈现位置的转换信息。 这是依赖项属性。
        public System.Windows.Media.Transform RenderTransform { get; set; }

        //获取或设置由 RenderTransform 声明的任何可能呈现转换的中心点,相对于元素的边界。 这是依赖项属性。
        public System.Windows.Point RenderTransformOrigin { get; set; }

        //获取或设置一个值,该值确定在呈现过程中,此元素的呈现是否应使用特定于设备的像素设置。 这是依赖项属性。
        public bool SnapsToDevicePixels { get; set; }

        //获取与此元素关联的所有触笔插件(自定义)对象的集合。
        protected System.Windows.Input.StylusPlugIns.StylusPlugInCollection StylusPlugIns { get; }

        //获取在此元素上捕获的所有触摸设备。
        public System.Collections.Generic.IEnumerable<System.Windows.Input.TouchDevice> TouchesCaptured { get; }

        //获取在此元素或其可视化树中的任何子元素上捕获的所有触摸设备。
        public System.Collections.Generic.IEnumerable<System.Windows.Input.TouchDevice> TouchesCapturedWithin { get; }

        //获取此元素上的所有触摸设备。
        public System.Collections.Generic.IEnumerable<System.Windows.Input.TouchDevice> TouchesDirectlyOver { get; }

        //获取在此元素或其可视化树中的任何子元素上的所有触摸设备。
        public System.Collections.Generic.IEnumerable<System.Windows.Input.TouchDevice> TouchesOver { get; }

        //获取或设置此元素的唯一标识符(用于本地化)。 这是依赖项属性。
        public string Uid { get; set; }

        //获取或设置用户界面 (UI) 此元素的可见性。 这是依赖项属性。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public System.Windows.Visibility Visibility { get; set; }
    }
//方法
public class UIElement : Visual, IAnimatable, IInputElement
    {
        //为指定的路由事件添加路由事件处理程序,并将该处理程序添加到当前元素的处理程序集合中。
        public void AddHandler(System.Windows.RoutedEvent routedEvent, Delegate handler);

        //为指定的路由事件添加路由事件处理程序,并将该处理程序添加到当前元素的处理程序集合中。 将 handledEventsToo 指定为 true,可为已标记为由事件路由中的其他元素处理的路由事件调用所提供的处理程序。
        public void AddHandler(System.Windows.RoutedEvent routedEvent, Delegate handler, bool handledEventsToo);

        //将处理程序添加到当前 EventRoute 事件处理程序集合的指定 UIElement 中。
        public void AddToEventRoute(System.Windows.EventRoute route, System.Windows.RoutedEventArgs e);

        //将动画应用到此元素的指定依赖属性。 任何现有动画均停止并替换为新动画。
        public void ApplyAnimationClock(System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationClock clock);

        //向此元素的指定依赖属性应用动画,并且可以指定当该属性已有正在运行的动画时所要执行的操作。
        public void ApplyAnimationClock(System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationClock clock, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);

        //定位子元素,并确定 UIElement 的大小。 父元素从它们的 ArrangeCore(Rect) 实现(或者是 WPF 框架级别等效项)调用此方法,以便形成递归布局更新。 此方法产生第二次布局更新。
        public void Arrange(System.Windows.Rect finalRect);

        //定义 WPF 核心级别排列布局定义的模板。
        protected virtual void ArrangeCore(System.Windows.Rect finalRect);

        //为此元素的指定要进行动画处理的属性启动动画。
        public void BeginAnimation(System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation);

        //为此元素的指定要进行动画处理的属性启动特定的动画,并可以指定当该属性已有正在运行的动画时所要执行的操作。
        public void BeginAnimation(System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);

        //尝试将鼠标强制捕获到此元素。
        public bool CaptureMouse();

        //尝试将触笔强制捕获到此元素。
        public bool CaptureStylus();

        //尝试将触摸屏输入强制捕获到此元素。
        public bool CaptureTouch(System.Windows.Input.TouchDevice touchDevice);

        //尝试将焦点设定到此元素上。
        public bool Focus();

        //为此元素上的指定属性返回基属性值,忽略任何可能来自正在运行或已停止的动画的动画值。
        public object GetAnimationBaseValue(System.Windows.DependencyProperty dp);

        //返回一个替代剪辑几何图形,它表示将 ClipToBounds 设置为 true 时要剪辑的区域。
        protected virtual System.Windows.Media.Geometry GetLayoutClip(System.Windows.Size layoutSlotSize);

        //当在派生类中重写时,如果不存在任何视觉父级,则返回 (UI) 父级的备用用户界面。
        protected internal virtual System.Windows.DependencyObject GetUIParentCore();

        //实现 HitTestCore(GeometryHitTestParameters) 以提供基元素命中测试行为(返回 GeometryHitTestResult)。
        protected override System.Windows.Media.GeometryHitTestResult HitTestCore(System.Windows.Media.GeometryHitTestParameters hitTestParameters);

        //protected override System.Windows.Media.GeometryHitTestResult HitTestCore (System.Windows.Media.GeometryHitTestParameters hitTestParameters);
        protected override System.Windows.Media.HitTestResult HitTestCore(System.Windows.Media.PointHitTestParameters hitTestParameters);

        //返回指定坐标上的当前元素中的输入元素(相对于当前元素的源)
        public System.Windows.IInputElement InputHitTest(System.Windows.Point point);

        //使元素排列状态(布局)无效。 排列状态失效后,该元素将更新其布局,更新将以异步方式发生,除非随后由 UpdateLayout() 强制执行。
        public void InvalidateArrange();

        //使元素度量状态(布局)无效。
        public void InvalidateMeasure();

        //使元素的呈现失效,并强制执行完整的新布局处理过程。 完成布局循环后调用 OnRender(DrawingContext)。
        public void InvalidateVisual();

        //更新 UIElement 的 DesiredSize。 父元素从其自身的 MeasureCore(Size) 实现调用此方法以形成递归布局更新。 调用此方法构成布局更新的第一个处理过程(“测量”处理过程)。
        public void Measure(System.Windows.Size availableSize);

        //在派生类中重写时,提供测量逻辑来适当地调整此元素的大小,兼顾任何子元素内容的大小。
        protected virtual System.Windows.Size MeasureCore(System.Windows.Size availableSize);

        //尝试将焦点从此元素移到其他元素。 移动焦点的方向由指导方向指定,该方向在此元素的可视父级的组织结构中解释。
        public virtual bool MoveFocus(System.Windows.Input.TraversalRequest request);

        //在调用对于此元素有意义的访问键时提供类处理。
        protected virtual void OnAccessKey(System.Windows.Input.AccessKeyEventArgs e);

        //重新调整子元素的大小时支持布局行为
        protected virtual void OnChildDesiredSizeChanged(System.Windows.UIElement child);

        //针对 Windows Presentation Foundation (WPF) 基础结构返回特定于类的 AutomationPeer 实现。
        protected virtual System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer();

        //当某个未处理的 DragEnter 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnDragEnter(System.Windows.DragEventArgs e);

        //当某个未处理的 DragLeave 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnDragLeave(System.Windows.DragEventArgs e);

        //当某个未处理的 DragOver 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnDragOver(System.Windows.DragEventArgs e);

        //当某个未处理的 DragEnter 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnDrop(System.Windows.DragEventArgs e);

        //当某个未处理的 GiveFeedback 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnGiveFeedback(System.Windows.GiveFeedbackEventArgs e);

        //使用所提供的事件数据引发 GotFocus 路由事件。
        protected virtual void OnGotFocus(System.Windows.RoutedEventArgs e);

        //当某个未处理的 GotKeyboardFocus 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e);

        //当某个未处理的 GotMouseCapture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnGotMouseCapture(System.Windows.Input.MouseEventArgs e);

        //当某个未处理的 GotStylusCapture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnGotStylusCapture(System.Windows.Input.StylusEventArgs e);

        //为在此元素上捕获触摸屏输入时发生的 GotTouchCapture 路由事件提供类处理。
        protected virtual void OnGotTouchCapture(System.Windows.Input.TouchEventArgs e);

        //当针对此元素引发未处理的 IsKeyboardFocusedChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsKeyboardFocusedChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //在此元素即将引发 IsKeyboardFocusWithinChanged 事件前调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsKeyboardFocusWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsMouseCapturedChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsMouseCapturedChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsMouseCaptureWithinChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsMouseCaptureWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsMouseDirectlyOverChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsMouseDirectlyOverChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsStylusCapturedChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsStylusCapturedChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsStylusCaptureWithinChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsStylusCaptureWithinChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当针对此元素引发未处理的 IsStylusDirectlyOverChanged 事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnIsStylusDirectlyOverChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //当某个未处理的 KeyDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnKeyDown(System.Windows.Input.KeyEventArgs e);

        //当某个未处理的 KeyUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnKeyUp(System.Windows.Input.KeyEventArgs e);

        //使用提供的事件数据引发 LostFocus 路由事件。
        protected virtual void OnLostFocus(System.Windows.RoutedEventArgs e);

        //当某个未处理的 LostKeyboardFocus 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e);

        //当某个未处理的 LostMouseCapture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnLostMouseCapture(System.Windows.Input.MouseEventArgs e);

        //当某个未处理的 LostStylusCapture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnLostStylusCapture(System.Windows.Input.StylusEventArgs e);

        //为在此元素失去触摸屏输入捕获时发生的 LostTouchCapture 路由事件提供类处理。
        protected virtual void OnLostTouchCapture(System.Windows.Input.TouchEventArgs e);

        //在 ManipulationBoundaryFeedback 事件发生时调用。
        protected virtual void OnManipulationBoundaryFeedback(System.Windows.Input.ManipulationBoundaryFeedbackEventArgs e);

        //在 ManipulationCompleted 事件发生时调用。
        protected virtual void OnManipulationCompleted(System.Windows.Input.ManipulationCompletedEventArgs e);

        //在 ManipulationDelta 事件发生时调用。
        protected virtual void OnManipulationDelta(System.Windows.Input.ManipulationDeltaEventArgs e);

        //在 ManipulationInertiaStarting 事件发生时调用。
        protected virtual void OnManipulationInertiaStarting(System.Windows.Input.ManipulationInertiaStartingEventArgs e);

        //在 ManipulationStarted 事件发生时调用。
        protected virtual void OnManipulationStarted(System.Windows.Input.ManipulationStartedEventArgs e);

        //为在首次创建操作处理器时发生的 ManipulationStarting 路由事件提供类处理。
        protected virtual void OnManipulationStarting(System.Windows.Input.ManipulationStartingEventArgs e);

        //当某个未处理的 MouseDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e);

        //当此元素引发未处理的 MouseEnter 附加事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseEnter(System.Windows.Input.MouseEventArgs e);

        //此元素引发未处理的 MouseLeave 附加事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseLeave(System.Windows.Input.MouseEventArgs e);

        //当此元素引发未处理的 MouseLeftButtonDown 路由事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 MouseLeftButtonUp 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 MouseMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseMove(System.Windows.Input.MouseEventArgs e);

        //当某个未处理的 MouseRightButtonDown 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseRightButtonDown(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 MouseRightButtonUp 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseRightButtonUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 MouseUp 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 MouseWheel 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnMouseWheel(System.Windows.Input.MouseWheelEventArgs e);

        //当某个未处理的 PreviewDragEnter 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewDragEnter(System.Windows.DragEventArgs e);

        //当某个未处理的 PreviewDragLeave 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewDragLeave(System.Windows.DragEventArgs e);

        //当某个未处理的 PreviewDragOver 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewDragOver(System.Windows.DragEventArgs e);

        //当某个未处理的 PreviewDrop 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewDrop(System.Windows.DragEventArgs e);

        //当某个未处理的 PreviewGiveFeedback 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewGiveFeedback(System.Windows.GiveFeedbackEventArgs e);

        //当某个未处理的 PreviewGotKeyboardFocus 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e);

        //当某个未处理的 PreviewKeyDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e);

        //当某个未处理的 PreviewKeyUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewKeyUp(System.Windows.Input.KeyEventArgs e);

        //当某个未处理的 PreviewKeyDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e);

        //当某个未处理的 PreviewMouseDown 附加路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseLeftButtonDown 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseLeftButtonUp 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseMove(System.Windows.Input.MouseEventArgs e);

        //当某个未处理的 PreviewMouseRightButtonDown 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseRightButtonDown(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseRightButtonUp 路由事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseRightButtonUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseUp(System.Windows.Input.MouseButtonEventArgs e);

        //当某个未处理的 PreviewMouseWheel 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewMouseWheel(System.Windows.Input.MouseWheelEventArgs e);

        //当某个未处理的 PreviewQueryContinueDrag 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewQueryContinueDrag(System.Windows.QueryContinueDragEventArgs e);

        //当某个未处理的 PreviewStylusButtonDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusButtonDown(System.Windows.Input.StylusButtonEventArgs e);

        //当某个未处理的 PreviewStylusButtonUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusButtonUp(System.Windows.Input.StylusButtonEventArgs e);

        //当某个未处理的 PreviewStylusDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusDown(System.Windows.Input.StylusDownEventArgs e);

        //当某个未处理的 PreviewStylusInAirMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusInAirMove(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 PreviewStylusInRange 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusInRange(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 PreviewStylusMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusMove(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 PreviewStylusOutOfRange 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理
        protected virtual void OnPreviewStylusOutOfRange(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 PreviewStylusSystemGesture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusSystemGesture(System.Windows.Input.StylusSystemGestureEventArgs e);

        //当某个未处理的 PreviewStylusUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewStylusUp(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 PreviewTextInput 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e);

        //为在触摸屏输入按下此元素时发生的 PreviewTouchDown 路由事件提供类处理。
        protected virtual void OnPreviewTouchDown(System.Windows.Input.TouchEventArgs e);

        //为在此元素内部移动触摸屏输入时发生的 PreviewTouchMove 路由事件提供类处理。
        protected virtual void OnPreviewTouchMove(System.Windows.Input.TouchEventArgs e);

        //为在此元素内部释放触摸屏输入时发生的 PreviewTouchUp 路由事件提供类处理。
        protected virtual void OnPreviewTouchMove(System.Windows.Input.TouchEventArgs e);

        //当某个未处理的 QueryContinueDrag 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnQueryContinueDrag(System.Windows.QueryContinueDragEventArgs e);

        //当某个未处理的 QueryCursor 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnQueryCursor(System.Windows.Input.QueryCursorEventArgs e);

        //在派生类中重写时,会参与由布局系统控制的呈现操作。 调用此方法时,不直接使用此元素的呈现指令,而是将其保留供布局和绘制在以后异步使用。
        protected virtual void OnRender(System.Windows.Media.DrawingContext drawingContext);

        //在派生类中重写时,会参与由布局系统控制的呈现操作。 如果元素的 RenderSize 已因布局更新而更改,则在布局更新之后以及呈现之前调用此方法。
        protected internal virtual void OnRenderSizeChanged(System.Windows.SizeChangedInfo info);

        //当某个未处理的 StylusButtonDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusButtonDown(System.Windows.Input.StylusButtonEventArgs e);

        //当某个未处理的 StylusButtonUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusButtonUp(System.Windows.Input.StylusButtonEventArgs e);

        //当某个未处理的 StylusDown 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusDown(System.Windows.Input.StylusDownEventArgs e);

        //当此元素引发未处理的 StylusEnter 附加事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusEnter(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 StylusInAirMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusInAirMove(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 StylusInRange 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusInRange(System.Windows.Input.StylusEventArgs e);

        //当此元素引发未处理的 StylusLeave 附加事件时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusLeave(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 StylusMove 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusMove(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 StylusOutOfRange 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusOutOfRange(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 StylusSystemGesture 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusSystemGesture(System.Windows.Input.StylusSystemGestureEventArgs e);

        //当某个未处理的 StylusUp 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnStylusUp(System.Windows.Input.StylusEventArgs e);

        //当某个未处理的 TextInput 附加事件在其路由中到达派生自此类的某个元素时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnTextInput(System.Windows.Input.TextCompositionEventArgs e);

        //为在此元素内按下触摸屏输入时发生的 TouchDown 路由事件提供类处理。
        protected virtual void OnTouchDown(System.Windows.Input.TouchEventArgs e);

        //为在触摸屏输入从此元素边界外部移动到其内部时发生的 TouchEnter 路由事件提供类处理
        protected virtual void OnTouchEnter(System.Windows.Input.TouchEventArgs e);

        //为在触摸屏输入从此 TouchLeave 边界内部移动到其外部时发生的 UIElement 路由事件提供类处理。
        protected virtual void OnTouchLeave(System.Windows.Input.TouchEventArgs e);

        //为在此元素内部移动触摸屏输入时发生的 TouchMove 路由事件提供类处理。
        protected virtual void OnTouchMove(System.Windows.Input.TouchEventArgs e);

        //为在此元素内部释放触摸屏输入时发生的 TouchUp 路由事件提供类处理。
        protected virtual void OnTouchUp(System.Windows.Input.TouchEventArgs e);

        //在此 UIElement 的父元素报告其基础可视父元素发生更改时,调用此方法。
        protected internal override void OnVisualParentChanged(System.Windows.DependencyObject oldParent);

        //当在派生类中重写时,返回将按指定焦点遍历方向接收焦点的元素,而不用实际将焦点移至该元素。
        public virtual System.Windows.DependencyObject PredictFocus(System.Windows.Input.FocusNavigationDirection direction);

        //引发特定路由事件。 在提供的 RoutedEventArgs 实例内标识将引发的 RoutedEvent(作为该事件数据的 RoutedEvent 属性)。
        public void RaiseEvent(System.Windows.RoutedEventArgs e);

        //从此元素中释放所有捕获的触摸设备。
        public void ReleaseAllTouchCaptures();

        //如果此元素具有鼠标捕获,则释放该捕获。
        public void ReleaseMouseCapture();

        //如果此元素具有触笔设备捕获,则释放该捕获。
        public void ReleaseStylusCapture();

        //尝试从此元素释放指定触摸设备。
        public bool ReleaseTouchCapture(System.Windows.Input.TouchDevice touchDevice);

        //从此元素中删除指定的路由事件处理程序。
        public void RemoveHandler(System.Windows.RoutedEvent routedEvent, Delegate handler);

        //返回序列化进程是否应在此类的实例上序列化 CommandBindings 属性的内容。
        public bool ShouldSerializeCommandBindings();

        //回序列化进程是否应在此类的实例上序列化 InputBindings 属性的内容。
        public bool ShouldSerializeInputBindings();

        //将相对于此元素的点转换为相对于指定元素的坐标。
        public System.Windows.Point TranslatePoint(System.Windows.Point point, System.Windows.UIElement relativeTo);

        //请确保此元素的所有可视子元素都正确地进行了布局更新。
        public void UpdateLayout();
    }
 //事件
public class UIElement : Visual, IAnimatable, IInputElement
    {
        //在输入系统报告出现以此元素为拖动目标的基础拖动事件时发生。
        public event System.Windows.DragEventHandler DragEnter;

        //在输入系统报告出现以此元素为拖动起点的基础拖动事件时发生。
        public event System.Windows.DragEventHandler DragLeave;

        //在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。
        public event System.Windows.DragEventHandler DragOver;

        //在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。
        public event System.Windows.DragEventHandler Drop;

        //当 Focusable 属性的值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler FocusableChanged;

        //在输入系统报告出现涉及此元素的基础拖放操作时发生。
        public event System.Windows.GiveFeedbackEventHandler GiveFeedback;

        //在此元素获得逻辑焦点时发生。
        public event System.Windows.RoutedEventHandler GotFocus;

        //在此元素聚焦于键盘时发生。
        public event System.Windows.Input.KeyboardFocusChangedEventHandler GotKeyboardFocus;

        //在此元素捕获鼠标时发生。
        public event System.Windows.Input.MouseEventHandler GotMouseCapture;

        //在此元素捕获触笔时发生。
        public event System.Windows.Input.StylusEventHandler GotStylusCapture;

        //在此元素上捕获触摸屏输入时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> GotTouchCapture;

        //在此元素的 IsEnabled 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsEnabledChanged;

        //在此元素的 IsHitTestVisible 依赖项属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsHitTestVisibleChanged;

        //在此元素的 IsKeyboardFocused 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsKeyboardFocusedChanged;

        //在此元素的 IsKeyboardFocusWithin 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsKeyboardFocusWithinChanged;

        //在此元素的 IsMouseCaptured 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsMouseCapturedChanged;

        //在此元素的 IsMouseCaptureWithinProperty 值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsMouseCaptureWithinChanged;

        //在此元素的 IsMouseDirectlyOver 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsMouseDirectlyOverChanged;

        //在此元素的 IsStylusCaptured 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsStylusCapturedChanged;

        //在此元素的 IsStylusCaptureWithin 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsStylusCaptureWithinChanged;

        //在此元素的 IsStylusDirectlyOver 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsStylusDirectlyOverChanged;

        //在此元素的 IsVisible 属性值更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler IsStylusDirectlyOverChanged;

        //当焦点在该元素上时按下某个键后发生。
        public event System.Windows.Input.KeyEventHandler KeyDown;

        //当焦点在该元素上时松开某个键后发生。
        public event System.Windows.Input.KeyEventHandler KeyUp;

        //在与当前 Dispatcher 关联的各种可视元素的布局更改时发生。
        public event EventHandler LayoutUpdated;

        //在此元素丢失逻辑焦点时发生。
        public event System.Windows.RoutedEventHandler LostFocus;

        //在键盘焦点不再位于此元素上时发生。
        public event System.Windows.Input.KeyboardFocusChangedEventHandler LostKeyboardFocus;

        //在此元素丢失鼠标捕获时发生。
        public event System.Windows.Input.MouseEventHandler LostMouseCapture;

        //在此元素丢失触笔捕获时发生。
        public event System.Windows.Input.StylusEventHandler LostStylusCapture;

        //在此元素失去触摸屏输入捕获时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> LostTouchCapture;

        //当操作遇到边界时发生。
        public event EventHandler<System.Windows.Input.ManipulationBoundaryFeedbackEventArgs> ManipulationBoundaryFeedback;

        //对于 UIElement 对象的操作和延时完毕时发生。
        public event EventHandler<System.Windows.Input.ManipulationCompletedEventArgs> ManipulationCompleted;

        //当输入设备在操作期间更改位置时发生。
        public event EventHandler<System.Windows.Input.ManipulationDeltaEventArgs> ManipulationDelta;

        //当输入设备在操作期间与 UIElement 对象失去联系且延时开始时发生。
        public event EventHandler<System.Windows.Input.ManipulationInertiaStartingEventArgs> ManipulationInertiaStarting;

        //当输入设备对 UIElement 对象开始操作时发生。
        public event EventHandler<System.Windows.Input.ManipulationStartedEventArgs> ManipulationStarted;

        //在首次创建操作处理器时发生。
        public event EventHandler<System.Windows.Input.ManipulationStartingEventArgs> ManipulationStarting;

        //在指针位于此元素上并且按下任意鼠标按钮时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseDown;

        //在鼠标指针进入此元素的边界时发生。
        public event System.Windows.Input.MouseEventHandler MouseEnter;

        //在鼠标指针离开此元素的边界时发生。
        public event System.Windows.Input.MouseEventHandler MouseLeave;

        //在鼠标指针位于此元素上并且按下鼠标左键时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseLeftButtonDown;

        //在鼠标指针位于此元素上并且松开鼠标左键时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseLeftButtonUp;

        //在鼠标指针位于此元素上并且移动鼠标指针时发生。
        public event System.Windows.Input.MouseEventHandler MouseMove;

        //在鼠标指针位于此元素上并且按下鼠标右键时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseRightButtonDown;

        //在鼠标指针位于此元素上并且松开鼠标右键时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseRightButtonUp;

        //在鼠标指针位于此元素上并且松开任意鼠标按钮时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseUp;

        //在鼠标指针位于此元素上并且用户滚动鼠标滚轮时发生。
        public event System.Windows.Input.MouseWheelEventHandler MouseWheel;

        //在输入系统报告出现以此元素为拖动目标的基础拖动事件时发生。
        public event System.Windows.DragEventHandler PreviewDragEnter;

        //在输入系统报告出现以此元素为拖动起点的基础拖动事件时发生。
        public event System.Windows.DragEventHandler PreviewDragLeave;

        //在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。
        public event System.Windows.DragEventHandler PreviewDragOver;

        //在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。
        public event System.Windows.DragEventHandler PreviewDrop;

        //在开始拖放操作时发生。
        public event System.Windows.GiveFeedbackEventHandler PreviewGiveFeedback;

        //在此元素聚焦于键盘时发生。
        public event System.Windows.Input.KeyboardFocusChangedEventHandler PreviewGotKeyboardFocus;

        //当焦点在该元素上时按下某个键后发生。
        public event System.Windows.Input.KeyEventHandler PreviewKeyDown;

        //当焦点在该元素上时松开某个键后发生。
        public event System.Windows.Input.KeyEventHandler PreviewKeyUp;

        //在此元素不再聚焦于键盘时发生。
        public event System.Windows.Input.KeyboardFocusChangedEventHandler PreviewLostKeyboardFocus;

        //在指针位于此元素上并且按下任意鼠标按钮时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseDown;

        //在鼠标指针位于此元素上并且按下鼠标左键时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseLeftButtonDown;

        //在鼠标指针位于此元素上并且松开鼠标左键时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseLeftButtonUp;

        //在鼠标指针位于此元素上并且移动鼠标指针时发生。
        public event System.Windows.Input.MouseEventHandler PreviewMouseMove;

        //在鼠标指针位于此元素上并且按下鼠标右键时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseRightButtonDown;

        //在鼠标指针位于此元素上并且松开鼠标右键时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseRightButtonUp;

        //在鼠标指针位于此元素上并且松开任意鼠标按钮时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseUp;

        //在鼠标指针位于此元素上并且用户滚动鼠标滚轮时发生。
        public event System.Windows.Input.MouseWheelEventHandler PreviewMouseWheel;

        //在拖放操作期间键盘或鼠标按钮的状态改变时发生。
        public event System.Windows.QueryContinueDragEventHandler PreviewQueryContinueDrag;

        //在指针位于此元素上并且按下触笔按钮时发生。
        public event System.Windows.Input.StylusButtonEventHandler PreviewStylusButtonDown;

        //在指针位于此元素上并且松开触笔按钮时发生。
        public event System.Windows.Input.StylusButtonEventHandler PreviewStylusButtonUp;

        //当触笔位于元素上且触及数字化器时发生
        public event System.Windows.Input.StylusDownEventHandler PreviewStylusDown;

        //在触笔掠过元素但并未实际接触数字化器时发生。
        public event System.Windows.Input.StylusEventHandler PreviewStylusInAirMove;

        //在触笔位于此元素上并且触笔与数字化器之间的距离近到足以检测到触笔时发生。
        public event System.Windows.Input.StylusEventHandler PreviewStylusInRange;

        //在触笔位于元素上并且移动触笔时发生。 数字化器在检测触笔时,触笔必须处于移动状态才会引发此事件,否则将改为引发 PreviewStylusInAirMove。
        public event System.Windows.Input.StylusEventHandler PreviewStylusMove;

        //在触笔与数字化仪之间的距离太远以致无法检测到触笔时发生。
        public event System.Windows.Input.StylusEventHandler PreviewStylusOutOfRange;

        //在用户采用某一种触笔笔势时发生。
        public event System.Windows.Input.StylusSystemGestureEventHandler PreviewStylusSystemGesture;

        //当触笔位于此元素上并且用户将触笔抬离数字化器时发生。
        public event System.Windows.Input.StylusEventHandler PreviewStylusUp;

        //在此元素以设备无关模式获取文本时发生。
        public event System.Windows.Input.TextCompositionEventHandler PreviewTextInput;

        //当悬停在此元素上方的手指触摸屏幕时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> PreviewTouchDown;

        //当悬停在此元素上方的手指在屏幕上移动时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> PreviewTouchMove;

        //当悬停在此元素上方的手指从屏幕上移开时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> PreviewTouchUp;

        //在拖放操作期间键盘或鼠标按钮的状态改变时发生。
        public event System.Windows.QueryContinueDragEventHandler QueryContinueDrag;

        //当请求显示光标时发生。 每次鼠标指针移至新位置时都会在一个元素上引发此事件,这意味着光标对象可能需要根据其新位置进行更改。
        public event System.Windows.Input.QueryCursorEventHandler QueryCursor;

        //在指针位于此元素上并且按下触笔按钮时发生。
        public event System.Windows.Input.StylusButtonEventHandler StylusButtonDown;

        //在指针位于此元素上并且松开触笔按钮时发生。
        public event System.Windows.Input.StylusButtonEventHandler StylusButtonUp;

        //在触笔位于此元素上且同时触及数字化器时发生。
        public event System.Windows.Input.StylusDownEventHandler StylusDown;

        //在触笔进入此元素的边界时发生。
        public event System.Windows.Input.StylusEventHandler StylusEnter;

        //在触笔掠过元素但并未实际接触数字化器时发生。
        public event System.Windows.Input.StylusEventHandler StylusInAirMove;

        //在触笔位于此元素上并且触笔与数字化器之间的距离近到足以检测到触笔时发生。
        public event System.Windows.Input.StylusEventHandler StylusInRange;

        //在触笔离开元素的边界时发生。
        public event System.Windows.Input.StylusEventHandler StylusLeave;

        //在触笔移到此元素上时发生。 触笔必须在位于数字化器上时移动,才会引发此事件。 否则将改为引发 StylusInAirMove。
        public event System.Windows.Input.StylusEventHandler StylusMove;

        //在触笔位于此元素上并且触笔与数字化器之间的距离太远以致无法检测到触笔时发生
        public event System.Windows.Input.StylusEventHandler StylusOutOfRange;

        //在用户采用某一种触笔笔势时发生。
        public event System.Windows.Input.StylusSystemGestureEventHandler StylusSystemGesture;

        //当触笔位于此元素上并且用户将触笔抬离数字化器时发生。
        public event System.Windows.Input.StylusEventHandler StylusUp;

        //在此元素以设备无关模式获取文本时发生。
        public event System.Windows.Input.TextCompositionEventHandler TextInput;

        //当悬停在此元素上方的手指触摸屏幕时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> TouchDown;

        //在触摸屏输入从此元素边界外部移动到其内部时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> TouchEnter;

        //在触摸屏输入从此元素边界内部移动到其外部时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> TouchLeave;

        //当悬停在此元素上方的手指在屏幕上移动时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> TouchMove;

        //当悬停在此元素上方的手指从屏幕上移开时发生。
        public event EventHandler<System.Windows.Input.TouchEventArgs> TouchUp;
    }

隧道事件带有前缀 Preview。隧道事件采用另一种方式,从根元素开始,向下遍历元素树,直到被处理或到达事件的源元素。这样上游元素就可以在事件到达源元素之前先行截取并进行处理。

冒泡事件是WPF路由事件中最为常见,它表示事件从源元素扩散(传播)到可视树,直到它被处理或到达根元素。这样您就可以针对源元素的上方层级对象处理事件。


2.1.6 FrameworkElement

提供 Windows Presentation Foundation (WPF) 元素的属性、事件和方法的 WPF 框架级别集。 此类表示所提供的 WPF 框架级别实现基于 UIElement 定义的 WPF 核心级别 API。

FrameworkElement 是 WPF framework-level element classes 与 WPF core-level set of UIElement presentation services之间的连接点 。 有关这些概念的详细信息,请参阅 WPF 体系结构

FrameworkElement 扩展 UIElement 并添加了以下功能:

  • 布局系统定义: FrameworkElement 为在UIElement中定义为虚拟成员的某些方法提供了特定的WPF框架级实现。最值得注意的是,FrameworkElement密封了某些WPF核心级别的布局替代,并提供了派生类应替代的WPF框架级别的等效项。FrameworkElement密封ArrangeCore,但提供ArrangeOverride。 这些更改反映了以下事实:在WPF框架级别,存在一个完整的布局系统,该系统可以呈现任何FrameworkElement派生的类。在WPF核心级别,某些成员将构成基于WPF的常规布局解决方案,但是并未定义布局系统的实际引擎。 有关更多信息,请参见布局。
  • 逻辑树一般的WPF编程模型通常表示为元素树。 支持将元素树表示为逻辑树,并在FrameworkElement级别实现了对在标记中定义该树的支持。 但是请注意,FrameworkElement故意没有定义内容模型,而是将这种责任留给派生类。 有关更多信息,请参见WPF中的树。
  • 对象生存期事件 当调用构造函数时,或者当元素首次加载到逻辑树中时,这经常被用到。 FrameworkElement 定义多个与对象生存期相关的事件,这些事件为涉及元素(如添加更多子元素)的代码隐藏操作提供有用的挂钩。 有关详细信息,请参阅 对象生存期事件
  • 数据绑定和动态资源引用支持 数据绑定和资源的属性级别支持由 DependencyProperty 类实现并在属性系统中使用,但是,可以解析存储为 Expression (编程构造的成员值,该构造是为数据绑定和动态资源提供基础的) 由 FrameworkElement实现 。 有关详细信息,请参阅 数据绑定概述 和 XAML 资源
  • 样式 FrameworkElement 定义 Style 属性。 但是,FrameworkElement 不支持对模板或修饰器。 这些功能由Control类如和ContentControl引入。
  • 更多动画支持 在WPF核心级别已经定义了一些动画支持.FrameworkElement通过实现BeginStoryboard和相关成员来扩展了动画支持。

从类层次结构可以看出,许多WPF类都直接或通过中间基类(例如Panel或Control)从FrameworkElement派生。

如果打算将FrameworkElement用作基类,则可能需要首先检查现有的派生类。 FrameworkElement提供了对许多基本方案的支持,但是从用于在可扩展应用程序标记语言(XAML)中创建用户界面(UI)的构造块的意义上讲,缺少一些“元素”所需的功能。 。 例如,FrameworkElement没有定义任何真实的内容模型。 FrameworkElement作为基类没有定义可以创建XAML子元素的属性。 特别是,您可能需要查看Control和ContentControl。

    public class FrameworkElement : UIElement, IFrameworkInputElement, IInputElement, ISupportInitialize, IHaveResources, IQueryAmbient
    {
        //################################字段###############################
        public static readonly System.Windows.DependencyProperty ActualHeightProperty;
        public static readonly System.Windows.DependencyProperty ActualWidthProperty;
        public static readonly System.Windows.DependencyProperty BindingGroupProperty;
        public static readonly System.Windows.RoutedEvent ContextMenuClosingEvent;
        public static readonly System.Windows.RoutedEvent ContextMenuOpeningEvent;
        public static readonly System.Windows.DependencyProperty ContextMenuProperty;
        public static readonly System.Windows.DependencyProperty CursorProperty;
        public static readonly System.Windows.DependencyProperty DataContextProperty;
        protected internal static readonly System.Windows.DependencyProperty DefaultStyleKeyProperty;
        public static readonly System.Windows.DependencyProperty FlowDirectionProperty;
        public static readonly System.Windows.DependencyProperty FocusVisualStyleProperty;
        public static readonly System.Windows.DependencyProperty ForceCursorProperty;
        public static readonly System.Windows.DependencyProperty HeightProperty;
        public static readonly System.Windows.DependencyProperty HorizontalAlignmentProperty;
        public static readonly System.Windows.DependencyProperty InputScopeProperty;
        public static readonly System.Windows.DependencyProperty LanguageProperty;
        public static readonly System.Windows.DependencyProperty LayoutTransformProperty;
        public static readonly System.Windows.RoutedEvent LoadedEvent;
        public static readonly System.Windows.DependencyProperty MarginProperty;
        public static readonly System.Windows.DependencyProperty MaxHeightProperty;
        public static readonly System.Windows.DependencyProperty MaxWidthProperty;
        public static readonly System.Windows.DependencyProperty MinHeightProperty;
        public static readonly System.Windows.DependencyProperty MinWidthProperty;
        public static readonly System.Windows.DependencyProperty NameProperty;
        public static readonly System.Windows.DependencyProperty OverridesDefaultStyleProperty;
        public static readonly System.Windows.RoutedEvent RequestBringIntoViewEvent;
        public static readonly System.Windows.RoutedEvent SizeChangedEvent;
        public static readonly System.Windows.DependencyProperty StyleProperty;
        public static readonly System.Windows.DependencyProperty TagProperty;
        public static readonly System.Windows.RoutedEvent ToolTipClosingEvent;
        public static readonly System.Windows.RoutedEvent ToolTipOpeningEvent;
        public static readonly System.Windows.DependencyProperty ToolTipProperty;
        public static readonly System.Windows.RoutedEvent UnloadedEvent;
        public static readonly System.Windows.DependencyProperty UseLayoutRoundingProperty;
        public static readonly System.Windows.DependencyProperty VerticalAlignmentProperty;
        public static readonly System.Windows.DependencyProperty WidthProperty;

        //################################属性###############################
        //获取此元素的呈现高度。
        public double ActualHeight { get; }

        //获取此元素的呈现宽度。
        public double ActualWidth { get; }

        //获取或设置用于该元素的 BindingGroup。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
        public System.Windows.Data.BindingGroup BindingGroup { get; set; }

        //获取或设置上下文菜单元素,此元素应在每次通过用户界面请求上下文菜单时显示, (UI) 此元素中。
        public System.Windows.Controls.ContextMenu ContextMenu { get; set; }

        //获取或设置在鼠标指针位于此元素上时显示的光标。
        public System.Windows.Input.Cursor Cursor { get; set; }

        //获取或设置元素参与数据绑定时的数据上下文。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
        public object DataContext { get; set; }

        //获取或设置在使用或定义主题样式时要用于引用此控件样式的键。
        protected internal object DefaultStyleKey { get; set; }

        //获取或设置文本和其他用户界面 (UI) 元素在任何控制其布局的父元素中的流动方向。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None)]
        public System.Windows.FlowDirection FlowDirection { get; set; }

        //获取或设置一个属性,该属性允许自定义此元素在捕获到键盘焦点时要应用于此元素的外观、效果或其他样式特征。
        public System.Windows.Style FocusVisualStyle { get; set; }

        //获取或设置一个值,该值指示此是否 FrameworkElement 应强制用户界面 (UI) 按属性所声明的方式呈现光标 Cursor 。
        public bool ForceCursor { get; set; }

        //获取或设置元素的建议高度。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double Height { get; set; }

        //获取或设置在父元素(如 Panel 或项控件)中组合此元素时所应用的水平对齐特征
        public System.Windows.HorizontalAlignment HorizontalAlignment { get; set; }

        //获取或设置属性值继承、资源键查找和RelativeSource FindAncestor 查找的范围限制
        protected internal System.Windows.InheritanceBehavior InheritanceBehavior { get; set; }

        //获取或设置此 FrameworkElement 使用的输入的上下文。
        public System.Windows.Input.InputScope InputScope { get; set; }

        //获取一个值,该值指示此元素是否已初始化,在由 XAML 处理器进行处理的过程中,或者通过显式 EndInit() 调用其方法进行初始化。
        public bool IsInitialized { get; }

        //获取一个值,该值指示是否已加载此元素以供呈现。
        public bool IsLoaded { get; }

        //获取或设置应用于某个元素的本地化/全球化语言信息。
        public System.Windows.Markup.XmlLanguage Language { get; set; }

        //获取或设置在执行布局时应该应用于此元素的图形转换方式
        public System.Windows.Media.Transform LayoutTransform { get; set; }

        //获取此元素的逻辑子元素的一个枚举器
        protected internal virtual System.Collections.IEnumerator LogicalChildren { get; }

        //获取或设置元素的外边距。
        public System.Windows.Thickness Margin { get; set; }

        //获取或设置元素的最大高度约束。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double MaxHeight { get; set; }

        //获取或设置元素的最大宽度约束。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double MaxWidth { get; set; }

        //获取或设置元素的最小高度约束。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double MinHeight { get; set; }

        //获取或设置元素的最小宽度约束。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double MinWidth { get; set; }

        //获取或设置元素的标识名称。 该名称提供引用,以便代码隐藏(如事件处理程序代码)可以引用标记元素,然后由 XAML 处理器在处理过程中构造该元素。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
        public string Name { get; set; }

        //获取或设置一个值,该值指示此元素是否并入主题样式中的样式属性。
        public bool OverridesDefaultStyle { get; set; }

        //获取此元素的逻辑父元素。
        public System.Windows.DependencyObject Parent { get; }

        //获取或设置本地定义的资源字典。
        [System.Windows.Markup.Ambient]
        public System.Windows.ResourceDictionary Resources { get; set; }

        //获取或设置此元素呈现时所使用的样式。
        public System.Windows.Style Style { get; set; }

        //获取或设置任意对象值,该值可用于存储关于此元素的自定义信息。
        [System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
        public object Tag { get; set; }

        //获取对此元素的模板父级的引用。 如果该元素不是通过模板创建的,则此属性无关。
        public System.Windows.DependencyObject TemplatedParent { get; }

        //获取或设置在用户界面 (UI) 中为此元素显示的工具提示对象。
        [System.ComponentModel.Bindable(true)]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.ToolTip)]
        public object ToolTip { get; set; }

        //获取直接在此元素上或在子元素中建立的触发器的集合。
        public System.Windows.TriggerCollection Triggers { get; }

        //获取或设置一个值,该值指示是否应向此元素的大小和位置布局应用布局舍入。
        public bool UseLayoutRounding { get; set; }

        //获取或设置在父元素(如面板或项控件)中组合此元素时所应用的垂直对齐特征。
        public System.Windows.VerticalAlignment VerticalAlignment { get; set; }

        //获取此元素内可视子元素的数目。
        protected override int VisualChildrenCount { get; }

        //获取或设置元素的宽度。
        [System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability = System.Windows.Readability.Unreadable)]
        public double Width { get; set; }


        //################################方法###############################
        //将提供的对象添加到此元素的逻辑树。
        protected internal void AddLogicalChild(object child);

        //在必要时生成当前模板的可视化树,然后返回一个值,该值指示可视化树是否由此调用重新生成。
        public bool ApplyTemplate();

        //实现 ArrangeCore(Rect)(在 UIElement 中定义为虚拟对象)并密封实现。
        protected override sealed void ArrangeCore(System.Windows.Rect finalRect);

        //在派生类中重写时,为 FrameworkElement 派生类定位子元素并确定大小。
        protected virtual System.Windows.Size ArrangeOverride(System.Windows.Size finalSize);

        //启动此元素的初始化过程。
        public virtual void BeginInit();

        //开始所提供的演示图板中包含的操作序列
        public void BeginStoryboard(System.Windows.Media.Animation.Storyboard storyboard);
        public void BeginStoryboard(System.Windows.Media.Animation.Storyboard storyboard, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);
        public void BeginStoryboard(System.Windows.Media.Animation.Storyboard storyboard, System.Windows.Media.Animation.HandoffBehavior handoffBehavior, bool isControllable);

        //尝试将此元素放入其所在的任何可滚动区域内的视图中。
        public void BringIntoView(System.Windows.Rect targetRectangle);
        public void BringIntoView();

        //指示元素的初始化过程已完成。
        public virtual void EndInit();

        //查找具有提供的标识符名的元素。
        public object FindName(string name);

        //搜索具有指定密钥的资源,如果未找到请求的资源,则会引发异常。
        public object FindResource(object resourceKey);

        //返回表示指定属性的绑定的 BindingExpression。
        public System.Windows.Data.BindingExpression GetBindingExpression(System.Windows.DependencyProperty dp);

        //获取指定的 DependencyObject 的 FlowDirection 附加属性值。
        public static System.Windows.FlowDirection GetFlowDirection(System.Windows.DependencyObject element);

        //返回剪切蒙版的形状。 如果布局系统尝试排列的元素大小超过可用显示空间,将会应用蒙版。
        protected override System.Windows.Media.Geometry GetLayoutClip(System.Windows.Size layoutSlotSize);

        //返回实例化的 ControlTemplate 可视化树中的命名元素。
        protected internal System.Windows.DependencyObject GetTemplateChild(string childName);

        //如果没有视觉父级,则返回此元素的备用逻辑父级
        protected internal override System.Windows.DependencyObject GetUIParentCore ();

        //重写 GetVisualChild(Int32),并从子元素集合中返回指定索引处的子元素
        protected override System.Windows.Media.Visual GetVisualChild(int index);

        //实现 FrameworkElement 的基本度量传递布局系统行为。
        protected override sealed System.Windows.Size MeasureCore(System.Windows.Size availableSize);

        //在派生类中重写时,测量子元素在布局中所需的大小,并确定由 FrameworkElement 派生的类的大小。
        protected virtual System.Windows.Size MeasureOverride(System.Windows.Size availableSize);

        //以提供的遍历方向将键盘焦点从此元素移到其他元素上。
        public override sealed bool MoveFocus(System.Windows.Input.TraversalRequest request);

        //在派生类中重写时,每当应用程序代码或内部进程调用 ApplyTemplate(),都将调用此方法。
        public virtual void OnApplyTemplate();

        //每当未处理的 ContextMenuClosing 路由事件在其路由中到达此类时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnContextMenuClosing(System.Windows.Controls.ContextMenuEventArgs e);

        //每当未处理的 ContextMenuOpening 路由事件在其路由中到达此类时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnContextMenuOpening(System.Windows.Controls.ContextMenuEventArgs e);

        //每当未处理的 GotFocus 事件在其路由中到达此元素时调用。
        protected override void OnGotFocus(System.Windows.RoutedEventArgs e);

        //引发 Initialized 事件。 每当在内部将 IsInitialized 设置为 true 时调用此方法。
        protected virtual void OnInitialized(EventArgs e);

        //每当更新此 FrameworkElement 的任何依赖属性的有效值时调用。 将在自变量参数中报告已更改的特定依赖属性。 重写 OnPropertyChanged(DependencyPropertyChangedEventArgs)。
        protected override void OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e);

        //引发 SizeChanged 事件,将指定的信息用作最终事件数据的一部分。
        protected internal override void OnRenderSizeChanged(System.Windows.SizeChangedInfo sizeInfo);

        //当此元素上使用的样式更改时(将使布局失效)调用。
        protected internal virtual void OnStyleChanged(System.Windows.Style oldStyle, System.Windows.Style newStyle);

        //每当未处理的 ToolTipClosing 路由事件在其路由中到达此类时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnToolTipClosing(System.Windows.Controls.ToolTipEventArgs e);

        //每当 ToolTipOpening 路由事件在其路由中到达此类时调用。 实现此方法可为此事件添加类处理。
        protected virtual void OnToolTipOpening(System.Windows.Controls.ToolTipEventArgs e);

        //当此元素父级在可视化树中发生更改时进行了调用。 重写 OnVisualParentChanged(DependencyObject)。
        protected internal override void OnVisualParentChanged(System.Windows.DependencyObject oldParent);

        //支持 FrameworkElement 的专用子类中的增量布局实现。 如果子元素包含无效属性,且该属性在元数据中标记为影响布局过程中父元素的测量或排列过程的因素,则调用 ParentLayoutInvalidated(UIElement)。
        protected internal virtual void ParentLayoutInvalidated(System.Windows.UIElement child);

        //根据提供的焦点移动方向,确定在此元素之后接收焦点的下一个元素,但不实际移动焦点。
        public override sealed System.Windows.DependencyObject PredictFocus(System.Windows.Input.FocusNavigationDirection direction);

        //提供一个可简化对 NameScope 注册方法访问的访问器。
        public void RegisterName(string name, object scopedElement);

        //从此元素的逻辑树中删除所提供的对象。 FrameworkElement 将更新受影响的逻辑树父指针,以便与此删除操作保持同步。
        protected internal void RemoveLogicalChild(object child);

        //为指定的依赖属性向此元素附加一个绑定。
        public System.Windows.Data.BindingExpression SetBinding(System.Windows.DependencyProperty dp, string path);
        public System.Windows.Data.BindingExpressionBase SetBinding(System.Windows.DependencyProperty dp, System.Windows.Data.BindingBase binding);

        //设置所提供元素的 FlowDirection 附加属性的值。
        public static void SetFlowDirection(System.Windows.DependencyObject element, System.Windows.FlowDirection value);

        //搜索具有指定名称的资源,并且为指定的属性设置一个指向该资源的资源引用。
        public void SetResourceReference(System.Windows.DependencyProperty dp, object name);

        //返回一个值,该值指示序列化过程是否应该序列化 Resources 属性的内容。
        public bool ShouldSerializeResources();

        //返回一个值,该值指示序列化过程是否应该序列化 Style 属性的内容。
        public bool ShouldSerializeStyle();

        //返回一个值,该值指示序列化过程是否应该序列化 Triggers 属性的内容。
        public bool ShouldSerializeTriggers();

        //搜索具有指定键的资源,如果找到,则返回该资源。
        public object TryFindResource(object resourceKey);

        //简化对 NameScope 注销方法的访问。
        public void UnregisterName(string name);

        //将默认样式重新应用至当前 FrameworkElement。
        public void UpdateDefaultStyle();


        //################################事件###############################
        //在元素上的任何上下文菜单关闭之前发生。
        public event System.Windows.Controls.ContextMenuEventHandler ContextMenuClosing;

        //在元素上的任何上下文菜单打开时发生。
        public event System.Windows.Controls.ContextMenuEventHandler ContextMenuOpening;

        //在此元素的数据上下文更改时发生。
        public event System.Windows.DependencyPropertyChangedEventHandler DataContextChanged;

        //初始化此 FrameworkElement 时发生。 此事件与 IsInitialized 属性的值从 false(或未定义)更改为 true 的情况相符。
        public event EventHandler Initialized;

        //当对元素进行布局、呈现,且可将其用于交互时发生。
        public event System.Windows.RoutedEventHandler Loaded;

        //当在此元素上调用 BringIntoView(Rect) 时发生。
        public event System.Windows.RequestBringIntoViewEventHandler RequestBringIntoView;

        //当此元素上的 ActualHeight 或 ActualWidth 属性的值发生更改时发生。
        public event System.Windows.SizeChangedEventHandler SizeChanged;

        //当此元素上的任何现有属性绑定的源值发生更改时发生。
        public event EventHandler<System.Windows.Data.DataTransferEventArgs> SourceUpdated;

        //当此元素上的任何属性绑定的目标值发生更改时发生。
        public event EventHandler<System.Windows.Data.DataTransferEventArgs> TargetUpdated;

        //在元素上的任何工具提示关闭之前发生。
        public event System.Windows.Controls.ToolTipEventHandler ToolTipClosing;

        //在元素上的任何工具提示打开时发生。
        public event System.Windows.Controls.ToolTipEventHandler ToolTipOpening;

        //当从加载的元素的元素树中移除元素时发生。
        public event System.Windows.RoutedEventHandler Unloaded;


        //################################接口###############################
        //有关此成员的说明,请参见 IsAmbientPropertyAvailable(String) 方法。
        bool IQueryAmbient.IsAmbientPropertyAvailable(string propertyName);              
    }

2.1.7 Control 类

表示用户界面 (UI) 元素的基类,这些元素使用 ControlTemplate 来定义其外观。

Control类是添加到应用程序中的许多控件的基类。 Control类定义极少的行为; 虽然可将添加 Control 到应用程序,但添加从Control 继承的控件(如ButtonListBox)更常见  。

Template属性(即ControlTemplate)指定的外观 Control 。 如果要更改控件的外观,但保留其功能,则应考虑创建一个新的ControlTemplate 而不是创建新类。 有关详细信息,请参阅 样式设置和模板化

如果要创建具有自定义行为的控件并允许其他人自定义其外观,则控件可以从 Control 类继承并定义 ControlTemplate 。 如果要扩展现有控件的行为,可以从继承自Control的类继承。

Control ControlTemplate在您的应用程序中不显示的,设置以下属性不起作用,除非 ControlTemplate 显式引用它们:

使用这些属性的常用方法是将中的元素绑定 ControlTemplate 到属性。 例如,如果希望控件根据属性的值更改颜色 Background ,可以将中元素的某些属性绑定 ControlTemplate 到 Background 。 使用 TemplateBinding 标记扩展 将控件的属性绑定到 ControlTemplate 中的元素。

Control 重写Focusable属性的元数据 ,并将其默认设置为 true 。 有关详细信息,请参阅 依赖项属性概述

    public class Control : FrameworkElement
    {
        //#########################字段###############################
        public static readonly DependencyProperty BorderBrushProperty;
        public static readonly DependencyProperty BorderThicknessProperty;
        public static readonly DependencyProperty BackgroundProperty;
        public static readonly DependencyProperty ForegroundProperty;
        public static readonly DependencyProperty FontFamilyProperty;
        public static readonly DependencyProperty FontSizeProperty;
        public static readonly DependencyProperty FontStretchProperty;
        public static readonly DependencyProperty FontStyleProperty;
        public static readonly DependencyProperty FontWeightProperty;
        public static readonly DependencyProperty HorizontalContentAlignmentProperty;
        public static readonly DependencyProperty VerticalContentAlignmentProperty;
        public static readonly DependencyProperty TabIndexProperty;
        public static readonly DependencyProperty IsTabStopProperty;
        public static readonly DependencyProperty PaddingProperty;
        public static readonly DependencyProperty TemplateProperty;
        public static readonly RoutedEvent PreviewMouseDoubleClickEvent;
        public static readonly RoutedEvent MouseDoubleClickEvent;


        //#########################属性###############################
        //获取或设置一个用于描述控件背景的画笔。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.Media.Brush Background { get; set; }

        //获取或设置一个用于描述控件的边框背景的画笔。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.Media.Brush BorderBrush { get; set; }

        //获取或设置控件的边框宽度。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.Thickness BorderThickness { get; set; }

        //获取或设置控件的字体系列。
        [System.ComponentModel.Bindable(true)]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.Font)]
        public System.Windows.Media.FontFamily FontFamily { get; set; }

        //获取或设置字号。
        [System.ComponentModel.Bindable(true)]
        [System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))]
        [System.Windows.Localizability(System.Windows.LocalizationCategory.None)]
        public double FontSize { get; set; }

        //获取或设置字体在屏幕上紧缩或加宽的程度。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.FontStretch FontStretch { get; set; }

        //获取或设置字体样式。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.FontStyle FontStyle { get; set; }

        //获取或设置指定字体的粗细。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.FontWeight FontWeight { get; set; }

        //获取或设置一个用于描述前景色的画笔。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.Media.Brush Foreground { get; set; }

        //获取一个值,该值指示控件是否支持滚动。
        protected internal virtual bool HandlesScrolling { get; }

        //获取或设置控件内容的水平对齐方式。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.HorizontalAlignment HorizontalContentAlignment { get; set; }

        //获取或设置一个值,该值指示是否将某个控件包含在 Tab 导航中。
        [System.ComponentModel.Bindable(true)]
        public bool IsTabStop { get; set; }

        //获取或设置控件内部的填充边距。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.Thickness Padding { get; set; }

        //获取或设置一个值,该值决定在用户使用 Tab 键在控件中导航时元素接收焦点的顺序。
        [System.ComponentModel.Bindable(true)]
        public int TabIndex { get; set; }

        //获取或设置控件模板。
        public System.Windows.Controls.ControlTemplate Template { get; set; }

        //获取或设置控件内容的垂直对齐方式。
        [System.ComponentModel.Bindable(true)]
        public System.Windows.VerticalAlignment VerticalContentAlignment { get; set; }


        //#########################方法###############################
        //调用以排列 Control 对象的内容并调整其大小。
        protected override System.Windows.Size ArrangeOverride(System.Windows.Size arrangeBounds);

        //调用以重新测量控件。
        protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint);

        //引发 MouseDoubleClick 路由事件。
        protected virtual void OnMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs e);

        //引发 PreviewMouseDoubleClick 路由事件。
        protected virtual void OnPreviewMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs e);

        //在控件模板发生更改时调用。
        protected virtual void OnTemplateChanged(System.Windows.Controls.ControlTemplate oldTemplate, System.Windows.Controls.ControlTemplate newTemplate);

        //返回 Control 对象的字符串表示形式。
        public override string ToString();

        //#########################事件###############################
        //在双击或多次单击鼠标按钮时发生。
        public event System.Windows.Input.MouseButtonEventHandler MouseDoubleClick;

        //在用户单击鼠标按钮两次或更多次时发生。
        public event System.Windows.Input.MouseButtonEventHandler PreviewMouseDoubleClick;
    }

 


总结:

Object:所有类的基类。

DispatcherObject:与线程管理相关,保证整个用户界面由单个线程拥有。

DependencyObject:依赖属性支持、附加属性支持。

Visual:为 WPF 中的呈现(界面绘图)提供支持,其中包括命中测试、坐标转换和边界框计算、绘图指令(剪裁、透明度、变换设置)等。

UIElement:提供元素布局特征的起点,从类中可以看出,这里已经开始响应用户的输入(包含路由事件、隧道事件),支持一些动画效果。

FrameworkElement:提供 Windows Presentation Foundation (WPF) 元素的属性、事件和方法的 WPF 框架级别集。 FrameworkElement 扩展 UIElement 并添加了以下功能:布局系统定义、逻辑树、对象生存期事件、数据绑定和动态资源引用支持、样式、更多动画支持。

Control:表示用户界面 (UI) 元素的基类,这些元素使用 ControlTemplate 来定义其外观。比如,背景、前景、字体等。

 

参考:

微软MSDN https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.controls?view=net-5.0

《深入浅出WPF》刘铁锰

《WPF编程宝典:使用C#2012和NET 4.5》

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值