内容控件与条目控件
内容控件(Content Controls):内容控件的最大的特征就是有一个Content属性
就比如Button按钮它是最常用的内容控件
页面代码:
<Canvas>
<TextBox Canvas.Left="151" Canvas.Top="69" Height="33" Name="textBox1" Width="172" Text="0" />
<RepeatButton x:Name="test" Delay="100" Interval="100" Click="test_Click" Width="172"
Content="确定" Height="61" Canvas.Left="151" Canvas.Top="121" />
</Canvas>
后台代码:按钮点击事件,每点击一次按钮时,TextBox控件的‘Text’自增一次
private void test_Click(object sender, RoutedEventArgs e)
{
var num = Convert.ToInt32(textBox1.Text);
textBox1.Text = (++num).ToString();
}
效果图:
控件特点:
1,内容属性的名称为Content;
2,只能由单一元素充当其内容。
2:条目控件(Items Controls):
条目控件首先都是继承自ItemsControl,在ItemsControl中有两个比较有意思的属性,Items和ItemsSource。
ItemsSource:ItemsSource常用于数据绑定,所以是一个非常实用的属性。
Items:Items属于ItemCollection的集合类型,每一个Item里面都可以放入一个Object类型对象。
ItemsSource常用于数据绑定,是一个非常实用的属性。
如Expander条目控件和GroupBox条目控件
代码:
<Grid>
<Expander Header="年龄组" Height="208" Margin="39,33,154,70" Name="expander1" Width="310">
<StackPanel>
<RadioButton Content="RadioButton1" Height="16" Name="radioButton1" />
<RadioButton Content="RadioButton2" Height="16" Name="radioButton2" />
</StackPanel>
</Expander> GroupBox
<GroupBox Header="年龄组" Height="208" Margin="399,106,83,155" Name="expander2" Width="310">
<StackPanel>
<RadioButton Content="RadioButton1" Height="16" Name="radioButton3" />
<RadioButton Content="RadioButton2" Height="16" Name="radioButton4" />
</StackPanel>
</GroupBox>
</Grid>
运行效果图:
条目控件的特点:
1,用于显示列表化的数据;
2,内容属性的名称为Items或ItemSource;
3,有自己的条目容器(Item Container)。