Visual Layer Overview(2)--Visual Tree

visual tree 包含一个应用 UI 中所有的可视化的元素( visual elements )。既然一个可视化元素中包含永久化的描画信息,可以认为 visual tree 是一个包含组成显示设备上输出的所有渲染信息的场景图。这棵树是应用直接创建的可视化元素的一个集合,无论使用代码创建的还是用标记语言创建的。 visual tree 还包括通过模版扩展的元素。
下面的例子定义了一个StackPanel元素
XAML
<StackPanel>
 <Label>User name:</Label>
 <TextBox />
 <Button Click="OnClick">OK</Button>
</StackPanel>
 
如果枚举组成 StackPanel 元素的可见对象的例子,可以得到下图所示的层次结构:
 

Rendering Order

 
 
 
 
Root visual visual tree 层次结构中最顶层的元素,在大多数应用程序中, root visual 的基类通常是Window 或者NavigationWindow 。可是,如果在 Win32 应用中 hosting 可见对象的话, root visual 就是 Win32 window 中最顶层的元素。 For more information, see Hosting Visual Objects in a Win32 Application.
 
Relationship to the Logical Tree
Windows Presentation Foundation 中的 logical tree 表示应用程序运行时的元素。虽然你不会直接的操作这个树,但是这种对应用的视角对于理解 property inheritance event routing 是很有帮助的。与 visual tree 不同, logical tree 可以表示不可见的 data objects ,例如: ListItem 。在大多数情况下, logical tree 几乎就是应用程序标记语言的近似映射。下面的代码显示了一个在标记语言中定义的 DockPanel 元素。
 
XAML
<DockPanel>
 <ListBox>
    <ListBoxItem>Dog</ListBoxItem>
    <ListBoxItem>Cat</ListBoxItem>
    <ListBoxItem>Fish</ListBoxItem>
  </ListBox>
 <Button Click="OnClick">OK</Button>
</DockPanel>
如果要枚举组成 DockPanel logical objects 的话,将得到下图的层次结构
 
visual tree logical tree 都与当前的应用的元素同步,反映任何元素的增加,删除或者修改。但是它们显示了应用的不同视图。与 visual tree, logical tree 并没有扩展控件的 ContentPresenter 元素。这意味着并没有 logical tree visual tree 之间的一一对应。实际上,在同一对象上调用 LogicalTreeHelper 's GetChildren me 方法和 VisualTreeHelper 's GetChild 方法,将得到不同的结果。
For more information on the logical tree, see Element Tree.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值