WPF 入门笔记之控件内容控件
一、控件类
在WPF中和用户交互的元素,或者说。能够接受焦点,并且接收键盘鼠标输入的元素所有的控件都继承于Control类。
1. 常用属性:
1.1 Foreground:前景画刷/前景色(文本颜色)
1.2 Background:背景画刷/背景色
//使用RBG设置颜色
Btn_1.Foreground = new SolidColorBrush(Color.FromRgb(, , ));
//使用颜色枚举设置颜色
Btn_1.Foreground = new SolidColorBrush(Colors.DarkGoldenrod);
//使用系统颜色枚举
Btn_1.Background = SystemColors.ActiveCaptionBrush;
1.3 FontFamily:设置字体
当FontFamily设置多个值表示,如果第一个字体不存在则使用第二个字体以此类推
<Button Name="Btn_1" FontFamily="Arial,Calibri,Cambria" >
<Button.Content>
this is button
</Button.Content>
</Button>
系统上安装的字体:Fonts.SystemFontFamilies
foreach (var item in Fonts.SystemFontFamilies)
{
lstBox_Message.Items.Add(item.Source);
}
设置任何元素的字体属性,属性的值会向下继承。如果给Window顶层元素设置字体,那么这个window下的所有元素都会继承这个字体
1.4 FontSize:字体大小
1.5 FontStyle:字体样式(斜体)
1.6 FontWeight:字体粗细
1.7 FontStretch:字体可以拉伸的角度
<StackPanel Orientation="Horizontal">
<Button Name="Btn_1" BorderBrush="Black" BorderThickness="2" Content="Border"></Button>
<Button Name="Btn_2" Content="FontStyle" FontStyle="Oblique" FontWeight="Black"></Button>
<Button Name="Btn_3" Content="FontWeight" FontStyle="Oblique"></Button>
<Button Name="Btn_4" Content="FontSize" FontSize="15"></Button>
<Button Name="Btn_5" Content="Fimaly" FontFamily="Arial"></Button>
</StackPanel>
1.8 BorderThickness:边框的大小
1.9 BorderBrush:边框画刷(边框颜色)
<Button Name="Btn_1" BorderBrush="Black" BorderThickness="2">
this is button
</Button>
1.10 Padding:内边距
1.11 HorizontalContentAlignment:内容水平方向的位置
1.12 VerticalContentAlignment:内容垂直方向的位置
1.13 Template:模板
1.14 IsTabStop:否将某个控件包含在 Tab 导航中
1.15 TabIndex:决定在用户使用 Tab 键在控件中导航时元素接收焦点的顺序
二、内容控件
内容控件,它可以包含显示一块内容。只能包含当个(只能包含的一个子元素)。和布局容器不同,布局容器可以不限制的包含子元素。内容控件都继承于ContentControl类
1. Content属性
Conent 只接收单一的对象(任何类型)
<StackPanel>
<!--直接设置Content属性-->
<Button Content="button" Margin="5"></Button>
<!--嵌套一个子元素-->
<Button Margin="5">
<TextBlock>this is TextBlock</TextBlock>
</Button>
<!--包含一个布局元素来实现嵌套多个子元素-->
<Button Margin="5">
<StackPanel>
<Label BorderBrush="Black" BorderThickness="1">this is Label</Label>
<Label BorderBrush="Aquamarine" BorderThickness="1" >this is Label</Label>
<Label BorderBrush="Beige" BorderThickness="1">this is Label</Label>
</StackPanel>
</Button>
</StackPanel>
2. 设置对齐方式和ToolTip
HorizontalContentAlignment:水平对齐
VerticalContentAlignment:垂直对齐
ToolTip:鼠标移动到该元素时,显示提示内容
<Button Content="button" ToolTip="ToolTip case" Margin="5" HorizontalContentAlignment="Left" ></Button>
<Button Content="button" Margin="5" HorizontalContentAlignment="Right" ></Button>
3. 带标题的内容控件
3.1 GroupBox
<GroupBox Header="GroupBox">
<StackPanel>
<RadioButton Margin="2">RadioButton1</RadioButton>
<RadioButton Margin="2">RadioButton2</RadioButton>
<RadioButton Margin="2">RadioButton3</RadioButton>
</StackPanel>
</GroupBox>
3.2 TabItem
<TabControl>
<TabItem Header="TabItem"></TabItem>
<TabItem Header="GroupBox"></TabItem>
<TabItem Header="Expander"></TabItem>
</TabControl>
3.3 Expander
<StackPanel>
<Expander Header="Expander">
<StackPanel>
<RadioButton Margin="2">RadioButton1</RadioButton>
<RadioButton Margin="2">RadioButton2</RadioButton>
<RadioButton Margin="2">RadioButton3</RadioButton>
</StackPanel>
</Expander>
</StackPanel>
WPF 入门笔记之控件内容控件的更多相关文章
- WPF入门(四)->线形区域Path内容填充之填充图(ImageBrush)
原文:WPF入门(四)->线形区域Path内容填充之填充图(ImageBrush) 前面我们提到了LinearGradientBrush可以用来画渐变填充图,那么我们同时也可以使用ImageBr ...
- WPF入门(四)->线形区域Path内容填充之渐变色(LinearGradientBrush)
原文:WPF入门(四)->线形区域Path内容填充之渐变色(LinearGradientBrush) 前面我们介绍到,Path对象表示一个用直线或者曲线连接的图形,我们可以使用Path.Data ...
- WPF知识点全攻略05- XAML内容控件
此处简单列举出布局控件外,其他常用的控件: Window:WPF窗口 UserControl:用户控件 Page:页 Frame:用来浏览Page页 Border:嵌套控件,提供边框和背景. Butt ...
- WPF学习笔记(1)——image控件图片不显示的问题
说明(2017-6-7 16:08:35): 1. 本来想用winform的,用winform就没这么多破事了. 2. 不过项目要用WPF,拉出一个mediaelement控件,视频正常显示. 3. ...
- WPF 入门笔记之事件
一.事件路由 1. 直接路由事件 起源于一个元素,并且不能传递给其他元素 MouserEnter 和MouserLeave 就是直接事件路由 2. 冒泡路由事件 在包含层次中向上传递,首先由引发的元素 ...
- WPF 入门笔记之布局
一.布局原则: 1. 不应显示的设定元素的尺寸,反而元素可以改变它的尺寸,并适应它们的内容 2. 不应使用平布的坐标,指定元素的位置. 3. 布局容器和它的子元素是共享可以使用的空间 4. 可以嵌套的 ...
- WPF 入门笔记之基础
一.创建WPF程序 1. App.xaml 相当于窗体的配置文件 2. xmlns:xml名称空间的缩写 xmlns="http://schemas.microsoft.com/winfx/ ...
- 【WPF学习】第二十章 内容控件
内容控件(content control)是更特殊的控件类型,它们可包含并显示一块内容.从技术角度看,内容控件时可以包含单个嵌套元素的控件.与布局容器不同的是,内容控件只能包含一个子元素,而布局容器主 ...
- WPF进阶技巧和实战03-控件(1-控件及内容控件)
所有控件都继承自System.Windows.Controls.Control类,这个类添加一些基本结构: 设置控件内容对齐方式 (HorizontalContentAlignment,Vertica ...
随机推荐
- ES6/ES2015核心内容(转载)
ES6其实就是ES2015,因为是2015年发布的,所以也叫ES2015.这个版本是JS的最新版本,很多浏览器还不支持,所有有了babel,专门把最新的JS转换一下,让大部分浏览器都支持的JS版本. ...
- WPF,通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色 4.0可用
<Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Proper ...
- SDP开发平台试用版上线!提供源码!!!!
SDP开发平台提供试用版!! SDP软件快速开发平台是一套面向对象的应用软件快速开发平台. 1.SDP 设计端--页面设计 通过简单的拖拉控件,或者快速生成控件,可以在几分钟快速制作一个页面:如图 通 ...
- Win8Metro(C#)数字图像处理--2.12Sobel边缘检测
原文:Win8Metro(C#)数字图像处理--2.12Sobel边缘检测 [函数名称] 图像Sobel边缘检测函数SobelEdgeProcess(WriteableBitmap src) [ ...
- PMC另类阐述
生产部门,坦克,铠甲战士,血厚硬气 业务部门,刺客,杀气十足,强势收割人头 采购部门,法师,在坦克身后持续输出 PMC,辅助,血不够厚扛不了伤害,输出不够拿不到人头,是团队中最容易被忽视的角色 坦克和 ...
- qt mingw64版本编译报错:incorrect register `%rax' used with `l' suffix(movl要改成mov)
环境:WIN10 编译器:mingw64的g++.exe 我的目的是把程序编译成64bit版本的,所以一开始遇到该错误是丈二和尚摸不着头脑,google了一圈也没找到准确的答案.后来从某些回答中大概发 ...
- 基于EF6的快速开发Web框架——Swift.Net
Swift.Net This Is A Light-Weight And Fast-Develop .Net Framework. Usage STEP 1 Create Your Entities ...
- 微信小程序把玩(三十一)wx.uploadFile(object), wx.downloadFile(object) API
原文:微信小程序把玩(三十一)wx.uploadFile(object), wx.downloadFile(object) API 反正我是没有测通这两个API!!!!不知道用的方式不对还是其他的!! ...
- The specified type member 'IsLock' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
var query = from C in objDb.GetDb<A>() join a in objDb.GetDb<B>().Where(m => m.Comput ...
- Add-AppxProvisionedPackage
原文: Add-AppxProvisionedPackage Adds an app package (.appx) that will install for each new user to a ...