
| GroupItem | Label | ListBoxItem | ListViewItem | NavigationWindow | | RepeatButton | ScrollViewer | StatusBarItem | ToggleButton | ToolTip | | UserControl | Window | | | |
包含控件:
Expander | GroupBox | HeaderedContentControl | TabItem |
|---|
Menu | MenuBase | ContextMenu | ComboBox | ItemsControl | ListBox |
|---|---|---|---|---|---|
ListView | TabControl | TreeView | Selector | StatusBar |
该类控件会自动使用相应的条目容器对提交给它的内容进行包装,合法的ItemsControl内容一定是集合,这个集合不会直接个给ItemsControl使用,而是先使用条目容器进行包装,这样的好处是允许程序员向ItemsControl提交各种类型的数据集合。
public class Person {
public int Id { set; get; }
public string Name { set; get; }
}
List<Person> people = new List<Person>()
{
new Person(){Id=1,Name="a"},
new Person(){Id=2,Name="b"},
new Person(){Id=3,Name="c"},
new Person(){Id=4,Name="d"},
};
//DisplayMebberPath只能显示字符串,更复杂的数据使用DataTemplate
this.lst.DisplayMemberPath = "Name";//显示数据的那个属性,listBox会调用这个属性的ToString()方法
this.lst.SelectedValuePath = "Id";//与SelectedValue属性配合使用,作为value的键
this.lst.ItemsSource = people;在UI上起装饰效果
ButtonChrome | ClassicBorderDecorator | ListBoxChrome | SystemDropShadowChrome | Border |
|---|---|---|---|---|
InkPresenter | BulletDecorator | Viewbox | AdornerDecorator |
包括控件:
Canvas | DockPanel | Grid | TabPenel | ToolBarOVerFlowPanel | StackPanel |
|---|---|---|---|---|---|
ToolBarPanel | UniformGrid | VirtualizingPanel | VirtualizingStackPanel | WrapPanel |
Grid适合场景:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
通过代码
this.grid.ColumnDefinitions.Add(new ColumnDefinition());
this.grid.RowDefinitions.Add(new RowDefinition());英文名称 | 中文名称 | 简写 | 换算 |
|---|---|---|---|
Pixel | 像素 | px | 图形基本单位 |
Inch | 英寸 | in | 1in=96px |
Centimeter | 厘米 | cm | 1cm=(96/2.54)px |
Point | 点 | pt | 1pt=(96/72)px |
值类型:
<RowDefinition Height="30px"/>
<RowDefinition Height="130*"/>
案例:

<!--Margin按照顺时针左、上、右、下-->
<Grid Margin="10" x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="120"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="4"/>
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="4"/>
<RowDefinition Height="*"/>
<RowDefinition Height="4"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<!--Grid.xxx等是附加属性-->
<TextBox Text="请选择部门并留言" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"/>
<ComboBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="4" />
<TextBox Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="5" BorderBrush="Black"/>
<Button Content="提交" Grid.Column="2" Grid.Row="4"/>
<Button Content="清除" Grid.Column="4" Grid.Row="4"/>
</Grid>内部元素可以横向和纵向紧凑排列,删除一个元素后面的自动移动到前面
适用场景:
常用的3个属性
属性名称 | 数据类型 | 可取值 | 描述 |
|---|---|---|---|
Orientation | Orientation枚举 | Horizongtal、Vertial | 横向排列还是纵向排列 |
HorizontalAlignment | HorizontalAlignment枚举 | Left、Center、Right、Stretch | 内部元素水平方向上的对齐方式 |
VerticalAlignment | VerticalAlignment枚举 | Top、Center、Bottom、Stretch | 内部元素竖直方向上的对齐方式 |
类似于Winform
使用场景:
<Canvas>
<TextBox Canvas.Left="12" Canvas.Top="20" Width="200"/>
</Canvas>内部采用流式布局,使用Orientation属性来控制流延伸的方向,使用HorizontalAlignment和VerticalAlignment两个属性控制内部控件的对齐。 =“20” Width=“200”/>
### DockPanel
+ 有一个重要属性LastChildFill,默认值为True,即最后一个元素的DockPanel.Dock属性被忽略,填满剩余空间
### WrapPanel
内部采用流式布局,使用Orientation属性来控制流延伸的方向,使用HorizontalAlignment和VerticalAlignment两个属性控制内部控件的对齐。