Welcome

首页 / 软件开发 / Silverlight / WPF and Silverlight学习笔记(十二)

WPF and Silverlight学习笔记(十二)2010-12-17 博客园 龙腾于海WPF and Silverlight学习笔记(十二):WPF Panel内容模型、Decorator内容模型及其他

一、Panel内容模型

Panel内容模型指从 System.Windows.Controls.Panel继承的控件,这些控件都是容器,可以在内部 承载其他的控件和子容器。Panel内容模型包含的容器有:

Canvas

DockPanel

Grid

TabPanel

ToolBarO verflowPanel

UniformGrid

StackPanel

ToolBarPanel

VirtualizingPanel

VirtualizingStackPanel

WrapPanel

< p>对于Panel模型,其包含一个Children属性,表示其所有的子控件和子容器的 集合,在XAML代码中可以省略<XXX.Children>标记,如:

 

1: <StackPanel x:Name="mainPanel">
2: <StackPanel x:Name="panelA">
3: <StackPanel.Children>
4: <Button>Button A</Button>
5: </StackPanel.Children>
6: </StackPanel>
7: <Button>Button B</Button>
8: <StackPanel x:Name="panelB">
9: </StackPanel>
10: </StackPanel>

也可以 通过代码,动态添加Children中的对象

1: // 定义一个 Button
2: Button btn = new Button();
3: btn.Content = "Button C";
4:
5: // 将Button添加到StackPanel 中
6: panelB.Children.Add(btn);