首页 / 软件开发 / Silverlight / WPF and Silverlight学习笔记(十一):WPF控件内容模型
WPF and Silverlight学习笔记(十一):WPF控件内容模型2010-12-17 博客园 龙腾于海WPF控件内容模型主要指派生于System.Windows.Controls.Control类的各种 控件,其主要分为四部分:ContentControlHeaderedContendControlItemsControl< /p>HeaderedItemsControl其继承关系请参考我上一篇博客的内容。这四个类用作为 WPF 中大多数控件的基类。使用这些内容模型的类可以 包含相同类型的内容,并以相同的方式处理该内容;可以放置在某个 ContentControl(或从 ContentControl 继承的类)中的任何类型的对象都可以 放置在具有其他三个内容模型中的任何一个的控件中。如:1: <Window x:Class="WPFControlContentModule.winOverView"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& quot;
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: Title="控件内容模型概述" Height="300" Width="400">
5: <Grid>
6: <Grid.ColumnDefinitions>
7: <ColumnDefinition />
8: <ColumnDefinition />
9: </Grid.ColumnDefinitions>
10: <Grid.RowDefinitions>
11: <RowDefinition />
12: <RowDefinition />
13: </Grid.RowDefinitions>
14:
15: <!--ContentControl示例(Button)-->
16: <TextBlock Text="ContentControl" Grid.Row="0" Grid.Column="0"/>
17: <Button Margin="5,20,5,5" Grid.Row="0" Grid.Column="0">
18: <Button.Content>
19: <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
20: <Image Source="Images/DVD.png" Width="48" Height="48" />
21: <TextBlock Text="DVD" HorizontalAlignment="Center" />
22: </StackPanel>
23: </Button.Content>
24: </Button>
25:
26: <!-- HeaderedContentControl示例(GroupBox)-->
27: <TextBlock Text="HeaderedContentControl" Grid.Row="0" Grid.Column="1"/>
28: <GroupBox Margin="5,20,5,5" Grid.Row="0" Grid.Column="1">
29: <GroupBox.Header>
30: <TextBlock Text="Header Text" />
31: </GroupBox.Header>
32: <GroupBox.Content>
33: <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
34: <Image Source="Images/DVD.png" Width="48" Height="48" />
35: <TextBlock Text="DVD" HorizontalAlignment="Center" />
36: </StackPanel>
37: </GroupBox.Content>
38: </GroupBox>
39:
40: <!--ItemsControl示例(ListBox)-->
41: <TextBlock Text="ItemsControl" Grid.Row="1" Grid.Column="0"/>
42: <ListBox Margin="5,20,5,5" Grid.Row="1" Grid.Column="0">
43: <ListBox.Items>
44: <TextBlock Text="List Item A" />
45: <Button Content="List Item B" />
46: <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
47: <Image Source="Images/DVD.png" Width="48" Height="48" />
48: <TextBlock Text="DVD" HorizontalAlignment="Center" VerticalAlignment="Center" />
49: </StackPanel>
50: </ListBox.Items>
51: </ListBox>
52:
53: <!-- HeaderedItemsControl示例(TreeView)-->
54: <TextBlock Text="HeaderedItemsControl" Grid.Row="1" Grid.Column="1"/>
55: <TreeView Margin="5,20,5,5" Grid.Row="1" Grid.Column="1">
56: <TreeViewItem>
57: <TreeViewItem.Header>
58: Tree Node A
59: </TreeViewItem.Header>
60: <TreeViewItem.Items>
61: <TextBlock Text="Node A - 1" />
62: <Button Content="Node A - 2" />
63: <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
64: <Image Source="Images/DVD.png" Width="48" Height="48" />
65: <TextBlock Text="DVD" HorizontalAlignment="Center" VerticalAlignment="Center" />
66: </StackPanel>
67: </TreeViewItem.Items>
68: </TreeViewItem>
69: <TreeViewItem>
70: <TreeViewItem.Header>
71: Tree Node B
72: </TreeViewItem.Header>
73: <TreeViewItem.Items>
74: <TextBlock Text="Node B - 1" />
75: <Button Content="Node B - 2" />
76: </TreeViewItem.Items>
77: </TreeViewItem>
78: </TreeView>
79: </Grid>
80: </Window>