祝紫山(大可山人)博客[GDI+,WPF, .Net图形图像]

WPF,WinForms,asp.net开发,图形图像处理系统研究[信奉:凡事靠自己] QQ:110-678-9933

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特性:如:事件处理、版面布局、样式、数据绑定、全球化。

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭