WPF and Silverlight學習筆記(十一):WPF控制項內容模型

來源:互聯網
上載者:User

WPF控制項內容模型主要指派生於System.Windows.Controls.Control類的各種 控制項,其主要分為四部分:

ContentControl

HeaderedContendControl

ItemsControl< /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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.