wpf控件的属性
HorizontalAlignment: 水平对齐
VerticalAlignment: 垂直对齐
Margin: 与父或兄控件的间距。有四个值,分别是左上右下。顺时针
Content: 显示的内容。
【按钮Button】
1.BorderBrush: 设置边框的颜色,eg:red
2.BorderThickness: 设置边框的厚度,eg:10
3.设置背景图片
<Button.Background> <ImageBrush ImageSource="{Binding Cover}" Stretch="UniformToFill"/> </Button.Background>
4.Foreground:前景色,一般是字体颜色
【RadioButton 单选框】
1.需要设置组名GroupName
2.绑定选中事件: Checked=" "
3.动态添加RadioButton:
//新建一个Button RadioButton rb=new RadioButton(); //指定组名 rb.GroupName="xx"; //指定显示的名称 rb.Content="男"; //是否选中 rb.IsChecked=false; //显示位置
rb.HorizontalAlignment=HorizontalAlignment.Left;
rb.VerticalAlignment=VerticalAlignment.Top;
grid.Children.Add(rb);
【CheckBox 复选框】
1.IsThreeState: 中间状态,当为true的时候,显示什么也没有。介于选中与未选中之间
2.获取选中状态的内容
private void btn_GetChkNames(object sender,RoutedEventArgs args) { string contentStr = ""; foreach(UIElement ue in grid.Children) { if(ue is CheckBox) { CheckBox chk = (CheckBox)ue; if(chk.IsChecked == true) { contentStr +=(contentStr!= ""?","+chk.Content.ToString(): chk.Content.ToString()); } } } MessageBox.Show(contentStr); }
记录编程的点滴,体会学习的乐趣