HandyControl是一套WPF控件库,它几乎重写了所有原生样式,同时包含80余款自定义控件(正逐步增加),下面我们开始使用。
1、准备
1.1 创建项目
C# WPF应用(.NET Framework)创建项目
1.2 添加包
1.3 在App.xaml中引用HandyControl的皮肤和主题:
1.4 窗体文件xaml添加引用
xmlns:hc="https://handyorg.github.io/handycontrol"
2、窗体
2.1 改Window为hc:Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:HandyControlTest" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800">
2.2 修改窗体的xaml.cs文件
修改窗体类名,否则报错:“分部声明一定不能指定不同的基类”
public partial class MainWindow : Window
↓
public partial class MainWindow : HandyControl.Controls.Window
2.3 扩展属性
2.4 代码修改
CloseButtonBackground="Blue" CloseButtonForeground="White"
CloseButtonHoverBackground="Red" CloseButtonHoverForeground="Black"
OtherButtonBackground="Green" OtherButtonForeground="White"
OtherButtonHoverBackground="Yellow" OtherButtonHoverForeground="Black"
2.5 运行结果
2.6 其它参数
NonClientAreaBackground用来设置了标题栏的背景色。NonClientAreaForeground用来设置标题栏的前景色,不仅仅可以用来设置标题的前景色,也可以设置NonClientAreaContent中控件的默认前景色。NonClientAreaHeight用来设置标题栏的高度。下面看一段代码:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:hc="https://handyorg.github.io/handycontrol" Title="WindowTest" Height="200" Width="400" NonClientAreaBackground ="LightBlue" NonClientAreaForeground="Red" NonClientAreaHeight="100">
运行效果:
3、 按钮
3.1 代码
发表评论