WPF笔记-控件

本文档详细介绍了WPF中的控件特性,包括控件的继承结构、内容对齐、背景与前景设置、字体样式、鼠标光标、内容属性、标签与按钮类型、点击模式、工具提示策略以及Popup与Tooltip的区别。还讨论了ScrollViewer控件的滚动功能和自定义滚动行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

空间类都继承自 System.Windows.Control

支持设置控件内容对齐方式

tab顺序

绘制背景,前景和边框

格式化文本内容的尺寸和字体


前景画刷,背景画刷

cmd.Background =  new SollidColorBrush(Colors.AliceBlue);

系统画刷颜色SystemColors.ControlColor

cmd.Foregroud = new SolidColorBrush(Color.FromRgb(red,green,blue));

透明颜色画刷Color.FromArgb(); Alpha


XAML : <Button Background = "Red">A Button</Button>


字体:

<Button name=”cmd" FontFamily="Times New Roman" FontSize="18">A Button</Button>

cmd.FontFamily = "Times New Roman";

cmd.FontSize = "18";

字体嵌入

1、添加字体文件.ttf Build Action设置为Resource

2. <Label FontFamily="./#Bayern" FontSize="20">This is an embedded font</Label>


鼠标光标

System.Windows.Input.Cursor

this.Cursor = Cursors.Wait;

<Button Cursor="Help">Help</Button>


content属性

对齐内容

HorizontalContentAlignment

VeritcalContentAlignment

<Button Padding="3">Well Padded</Button>


标签label

Label Target 隐藏属性。


按钮buttonbase

Button

CheckBox

RadioButton


ClickMode属性


工具提示 tooltip

<Button ToolTip="This is my tooltip">I have a tooltip</Button>

提示放置策略

1.根据鼠标的当前位置

2.根据悬停鼠标的元素的位置

Placement  Left Right Top Bottom

3.根据另一个元素(或窗口)的位置

4.使用偏移

5.使用绝对坐标

6.使用在运行时计算的结果

ToolTipService.InitialShowDelay="1"

<Button ToolTip="xxxxx" ToolTipService.Placement="Bottom">xxx</Button>


Popup

different between Popup and ToolTop

1 Popup不会自动显示需要设置它的IsOpen属性

2 Popup.StaysOpen

3 PopupAnimation进入视线的方式

4 可以接受焦点

5 在System.Windows.Controls.Primitive命名空间中


特殊容器控件

ScrollViewer

VericalScrollBarVisibility 禁止显示

LineUp() LineDown() PageUp() PageDown()

LineLeft() LineRight() PageLeft PageRight()

ScrollToEnd() ScrollToHome()

ISrollInfo自定义滚动


带标题的内容控件























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值