WPF中的可视化对象(Visual)

简介: 原文:WPF中的可视化对象(Visual) 这是MSDN对Visual的解释:Visual class:Provides rendering support in WPF, which includes hit test...
原文: WPF中的可视化对象(Visual)

这是MSDN对Visual的解释:
Visual class:
Provides rendering support in WPF, which includes hit testing, coordinate transformation, and bounding box calculations.

下面是关于Visual类的继承关系图,它清楚地表明了相关的层次关系:
System.Object
        System.Windows.Threading.DispatcherObject
                System.Windows.DependencyObject
                        System.Windows.Media.Visual
                                System.Windows.Media.ContainerVisual (支持包含其他Visual对象)
                                        System.Windows.Media.DrawingVisual
                                        System.Windows.Media.HostVisual
                                System.Windows.UIElement
                                        System.Windows.FrameworkElement
                                                System.Windows.Documents.Adorner
                                                System.Windows.Documents.AdornerLayer
                                                System.Windows.Documents.DocumentReference
                                                System.Windows.Documents.FixedPage
                                                System.Windows.Documents.Glyphs
                                                System.Windows.Documents.PageContent
                                                System.Windows.Interop.HwndHost
                                                Microsoft.Windows.Themes.ScrollChrome
                                                Microsoft.Windows.Themes.BulletChrome
                                                Microsoft.Windows.Themes.ScrollChrome
                                                System.Windows.Controls.Panel
                                                System.Windows.Controls.Control
                                                System.Windows.Controls.AccessText
                                                System.Windows.Controls.AdornedElementPlaceholder
                                                System.Windows.Controls.Decorator
                                                System.Windows.Controls.ContentPresenter
                                                System.Windows.Controls.Image
                                                System.Windows.Controls.InkCanvas
                                                System.Windows.Controls.ItemsPresenter
                                                System.Windows.Controls.MediaElement
                                                System.Windows.Controls.Page
                                                System.Windows.Controls.TextBlock
                                                System.Windows.Controls.ToolBarTray
                                                System.Windows.Controls.Viewport3D
                                                System.Windows.Shapes.Shape
                                                System.Windows.Controls.Primitives.GridViewRowPresenterBase
                                                System.Windows.Controls.Primitives.DocumentPageView
                                                System.Windows.Controls.Primitives.Popup
                                                System.Windows.Controls.Primitives.TickBar
                                                System.Windows.Controls.Primitives.Track
                                System.Windows.Media.Media3D.Viewport3DVisual 

再简洁点:
System.Object
        System.Windows.Threading.DispatcherObject
                System.Windows.DependencyObject
                        System.Windows.Media.Visual
                                System.Windows.Media.ContainerVisual
                                System.Windows.UIElement
                                        System.Windows.FrameworkElement
                                System.Windows.Media.Media3D.Viewport3DVisual

Visual:是WPF中用以呈现点击测试(与一个点、矩形、区域或其它对象之间执行像素级的点击检测,比如判断鼠标是否在一个对象内等),坐标转换和计算可视化对象尺寸范围的类。

以下是Visual,UIElement,FrameworkElement的构造示意:
public abstract class Visual : DependencyObject
public class UIElement : Visual, IAnimatable, IInputElement
public class FrameworkElement : UIElement, IFrameworkInputElement, IInputElement, ISupportInitialize

从Visual的构造看,它是继承于DependencyObject的抽像类。
而UIElement继承自Visual,FrameworkElement又继承自UIElement。

Visual是所有FrameworkElement的抽象基类。它为在WPF中写新的控件提供了入口点,在许多方面,你可以把它想像成为相当于Win32应用程序模式下的window句柄(HWND)。
Visual对象是WPF的核心对象,其主要角色是提供呈现支持。用户控件,如按钮Button和文本框TextBox,都从Visual类继承,并使用Visual定义的属性来维持它们的呈现数据。

Visual对象支持:
输入显示: 显示可视化的内容。
变换: 对可视化对象进行变换(比如尺寸变换、坐标转换等)。
裁切: 对可视化对象在裁切区域进行裁切之后显示。
点击测试(Hit testing):  检测一个指定的坐标(点)或几何对象是否在指定的可视化对象之范围内。
矩形范围计算:  确定Visual对象所涵盖的矩形区域。

架构上,Visual对象不支持包括其他应用程序开发需要的其他WPF特性:如:事件处理、版面布局、样式、数据绑定、全球化。

目录
相关文章
|
7月前
|
C#
2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>
2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>
53 0
WPF界面异常:未将对象引用设置到对象实例
WPF界面异常:未将对象引用设置到对象实例
|
C#
WPF中,怎样将XAML代码加载为相应的对象?
原文:WPF中,怎样将XAML代码加载为相应的对象? 在前面“在WPF中,如何得到任何Object对象的XAML代码?”一文中,我介绍了使用System.Windows.Markup.XamlWriter.Save(objName)得到任何Object对象的XAML代码。
889 0
|
C#
WPF中实现图片文件转换成Visual对象,Viewport3D对象转换成图片
原文:WPF中实现图片文件转换成Visual对象,Viewport3D对象转换成图片 1、图片文件转换成Visual对象         private Visual CreateVisual(string imageFileName)        {            BitmapImag...
1157 0
|
C#
WinForm和WPF颜色对象的转换
原文:WinForm和WPF颜色对象的转换 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huangli321456/article/details/52956846 ...
849 0
|
C# 前端开发 Windows
在WPF应用程序中利用IEditableObject接口实现可撤销编辑的对象
原文:在WPF应用程序中利用IEditableObject接口实现可撤销编辑的对象 这是我辅导的一个项目开发中的例子,他们是用WPF做界面开发,在学习了如何使用MVVM来实现界面与逻辑的分离,并且很好的数据更新之后,有一个疑问就是,这种双向的数据更新确实很不错,但如果我们希望用户可以撤销修改怎么办呢?其实这个功能,很早就有,甚至在原先的Windows Forms里面也可以实现。
926 0
|
C# 存储
【值转换器】 WPF中Image数据绑定Icon对象
原文:【值转换器】 WPF中Image数据绑定Icon对象        这是原来的代码:                这里的MenuIcon是string类型,MenuIcon = "/Image/Tux.ico"。
873 0
|
C#
WPF中实现PropertyGrid(用于展示对象的详细信息)的三种方式
原文:WPF中实现PropertyGrid(用于展示对象的详细信息)的三种方式 由于WPF中没有提供PropertyGrid控件,有些业务需要此类的控件。
1815 0
|
C# 数据可视化 容器
WPF利用VisualTreeHelper遍历寻找对象的子级对象或者父级对象
原文:WPF利用VisualTreeHelper遍历寻找对象的子级对象或者父级对象 简介   本文将完整叙述我利用VisualTreeHelper实现题述功能的全部过程,想直接看函数实现的朋友可以跳到函数实现部分。
1536 0
|
C#
WPF解决方案------调用线程无法访问此对象,因为另一个线程拥有该对象
WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案 在这里以播放图片为例进行说明,代码如下: void _Timer_Elapsed(object sender, ElapsedEventArgs e) { this.
4923 0