Image控件:显示一张图片,source:指定图片位置。Stretch:图片的显示方式 None不会调整大小,Fill拉伸,Uniform保持宽高比, UniformFill保持宽高比的同时填充区域
// 图片位置 填充方式 大小
- <Image Source=".\Images\xx.png" Stretch="UniformToFill" Width="16" Height="16" />
Label控件:显示文本信息
//(属性) 名字, 显示文本 水平布局方式 边距 Grid控件 显示的位置
- <Label x:Name="label" Content="Players" HorizontalAlignment="Left" Margin="10,5,0,0" Grid.Row="2"
- //垂直布局方式 前景色 字体
- VerticalAlignment="Top" Foreground="black" FontFamily="Times New Roman" />
TextBlock控件:可以显示多行文本,与ScrollViewer配合使用
// 显示的文本 边距
- <TextBlock Text="Visual C# 6 for Windows. You can Press at http://www.baidu.com." Margin="0, 10,0,0" Padding="20,0,0,0"
- // 自动换行 水平显示的布局 垂直布局 大小
- TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Height="39"/>
Button控件:按钮,点击
// 名字 显示文本 Canvas布局 大小 点击事件方法
- <Button Name="ok" Content="_OK" Canvas.Right="12" Canvas.Bottom="10" Width="75" Click="Button_Click"/>
TextBox控件:可以显示文本,也可以输入文本信息
// 名字 水平布局 大小 边距 Grid的第二行
- <TextBox x:Name="newPlayerTextBox" HorizontalAlignment="Left" Height="23" Margin="252,31,0,0" Grid.Row="2"
- //自动换行 垂直布局 大小
- TextWrapping="Wrap" VerticalAlignment="Top" Width="166"/>
CheckBox控件:可以显示一个开关选项,单选框
// 显示的文本 水平布局 边距 垂直布局
- <CheckBox Content="computer" HorizontalAlignment="Left" Margin="11,33,0,0" VerticalAlignment="Top"
- //名字 是否选择 绑定的数据
- Name="playCheck" IsChecked="{Binding Path=PlayAgainstComputer}"/>
RadioButton控件:可以让用户从多个RadioButton的选项中选择一个(单选)
//三个RadioButton选项,一次只能选择其中一个选项
// 选项显示的内容 水平布局 边距 垂直布局
- <RadioButton Content="Dumb" HorizontalAlignment="Left" Margin="37,41,0,0" VerticalAlignment="Top"
- //名字 选中的值
- Name="dumbAIRadioButton" Checked="dumbAIRadioButton_Checked"/>
- <RadioButton Content="Good" HorizontalAlignment="Left" Margin="37,62,0,0" VerticalAlignment="Top" Name="goodAIRadioButton" Checked="goodAIRadioButton_Checked"/>
- <RadioButton Content="Cheats" HorizontalAlignment="Left" Margin="37,83,0,0" VerticalAlignment="Top" Name="cheatingAIRadioButton" Checked="cheatingAIRadioButton_Checked"/>
ConboBox控件:包含多个选项的下拉列表
// 水平布局 边距 垂直布局 大小
- <ComboBox HorizontalAlignment="Left" Margin="196,58,0,0" VerticalAlignment="Top" Width="86"
- //名字 选项的内容(绑定的数据)
- Name="numberOfPlayersComboBox" ItemsSource="{Binding Source={StaticResource numberOfPlayersData}}"
- //选项值 绑定的数据
- SelectedValue="{Binding Path=NumberOfPlayers}" >
- //选项内容(不使用绑定数据)
- <ComboBoxItem>value</ComboBoxItem>
- <ComboBoxItem>val</ComboBoxItem>
- </ComboBox>
Table Control控件:布局控件,可以对页面上的其他控件进行分组
// 占用两行 Canvas控件中位置 大小 Grid控件的 位置
- <TabControl Grid.RowSpan="2" Canvas.Left="10" Canvas.Top="2" Width="408" Height="208" Grid.Row="1">
- //两个分组的名字
- <TabItem Header="Game"/>
- <TabItem Header="Computer Player"/>
- </TabControl>
ListBox控件:多项选择框
// 名字 水平布局 大小 边距 Grid第二行
- <ListBox x:Name="playerNamesListBox" HorizontalAlignment="Left" Height="155" Margin="10,31,0,0" Grid.Row="2"
- //垂直布局 大小 绑定的数据(显示的数据)
- VerticalAlignment="Top" Width="227" ItemsSource="{Binding Path=PlayerNames}"
- //选择改变的事件方法
- SelectionChanged="playerNamesListBox_SelectionChanged"/>
Menu菜单控件:MunuItem控件,
// 背景 色 字体加粗 前景色
- <Menu Background="Black" FontWeight="Bold" Foreground="White" >
- // File菜单
- <MenuItem Header="_File">
- // File菜单的子选项 NewGame 前景色 大小
- <MenuItem Header="_New Game..." Foreground="Black" Width="200"
- // 命令参数 绑定的本地数据
- Command="local:GameViewModel.StartGameCommand" />
- // File菜单的子选项Open 大小 前景色
- <MenuItem Header="_Open" Width="200" Foreground="Black"/>
- // File菜单的子选项Save 大小 前景色 命令参数
- <MenuItem Header="_Save" Width="200" Foreground="Black" Command="Save">
- // 菜单的图标
- <MenuItem.Icon>
- <Image Source="Images\base_floppydisk_32.png" Width="20" />
- </MenuItem.Icon>
- </MenuItem>
- //分割线
- <Separator Width="145" Foreground="Black"/>
- </Menu>