《学习笔记》Layui-WPF按钮美化
一睹为快:
要点回顾:接着我们上一期的自定义窗体美化用到自定义属性DependencyProperty,快速生成自定义属性快捷键Propdp+双击Tab键,调用自定义属性如:窗体头部高度:Height="{Binding Path=HearderHieght, RelativeSource={RelativeSource Mode=TemplatedParent}}" Background="{TemplateBinding Background}",接下来我们美化按钮
1.创建文件夹ButtonStyle文件夹并且自定义控件取名为LayButton
2.双击LayButton让当前类文件继承Button
3.由于按钮由文字内容以及带边框的容器组成,那么我们联想到Border+ContentPresenter组成,Style样式为
4.组合完成图,Style样式已完成返回LayButtonm.CS文件实现功能
public class LayButton : Button { static LayButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(LayButton), new FrameworkPropertyMetadata(typeof(LayButton))); } public CornerRadius BorderRadius { get { return (CornerRadius)GetValue(BorderRadiusProperty); } set { SetValue(BorderRadiusProperty, value); } } // Using a DependencyProperty as the backing store for BorderRadius. This enables animation, styling, binding, etc... public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register("BorderRadius", typeof(CornerRadius), typeof(LayButton)); public Brush HoverBorderBrush { get { return (Brush)GetValue(HoverBorderBrushProperty); } set { SetValue(HoverBorderBrushProperty, value); } } // Using a DependencyProperty as the backing store for HoverBorderBrush. This enables animation, styling, binding, etc... public static readonly DependencyProperty HoverBorderBrushProperty = DependencyProperty.Register("HoverBorderBrush", typeof(Brush), typeof(LayButton)); }