WPF and Silverlight Learning Notes (12): WPF panel content model, decorator content model, and other
I. Panel content model
The Panel content model refers to controls that inherit from System.Windows.Controls.Panel, which are containers that can host other controls and child containers internally. The Panel content model contains containers that are:
Canvas
DockPanel
Grid
TabPanel
Toolbaro Verflowpanel
UniformGrid
StackPanel
Toolbarpanel
Virtualizingpanel
VirtualizingStackPanel
WrapPanel
< p> for the panel model, it contains a children property that represents the collection of all its child controls and child containers, which can be omitted from the XAML code <XXX. Children> tags, such as:
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>
You can also dynamically add objects in children through code
1: // 定义一个 Button
2: Button btn = new Button();
3: btn.Content = "Button C";
4:
5: // 将Button添加到StackPanel 中
6: panelB.Children.Add(btn);