标签:try sch nts triggers override font tac shadow readonly
创建ButtonEx类
public class ButtonEx : Button
{
static ButtonEx()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonEx), new FrameworkPropertyMetadata(typeof(ButtonEx)));
}
///
/// 按钮类型
///
public ButtonType ButtonType
{
get { return (ButtonType)GetValue(ButtonTypeProperty); }
set { SetValue(ButtonTypeProperty, value); }
}
public static readonly DependencyProperty ButtonTypeProperty =
DependencyProperty.Register("ButtonType", typeof(ButtonType), typeof(ButtonEx), new PropertyMetadata(ButtonType.Normal));
///
/// 图片
///
public ImageSource Icon
{
get { return (ImageSource)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(ImageSource), typeof(ButtonEx), new PropertyMetadata(null));
///
/// 圆角
///
public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ButtonEx), new PropertyMetadata(new CornerRadius(0)));
///
/// 鼠标悬停字体颜色
///
public Brush MouseOverForeground
{
get { return (Brush)GetValue(MouseOverForegroundProperty); }
set { SetValue(MouseOverForegroundProperty, value); }
}
public static readonly DependencyProperty MouseOverForegroundProperty =
DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(ButtonEx), new PropertyMetadata());
///
/// 鼠标按下文字颜色
///
public Brush MousePressedForeground
{
get { return (Brush)GetValue(MousePressedForegroundProperty); }
set { SetValue(MousePressedForegroundProperty, value); }
}
public static readonly DependencyProperty MousePressedForegroundProperty =
DependencyProperty.Register("MousePressedForeground", typeof(Brush), typeof(ButtonEx), new PropertyMetadata());
///
/// 鼠标悬停边框颜色
///
public Brush MouseOverBorderbrush
{
get { return (Brush)GetValue(MouseOverBorderbrushProperty); }
set { SetValue(MouseOverBorderbrushProperty, value); }
}
public static readonly DependencyProperty MouseOverBorderbrushProperty =
DependencyProperty.Register("MouseOverBorderbrush", typeof(Brush), typeof(ButtonEx), new PropertyMetadata());
///
/// 鼠标悬停背景颜色
///
public Brush MouseOverBackground
{
get { return (Brush)GetValue(MouseOverBackgroundProperty); }
set { SetValue(MouseOverBackgroundProperty, value); }
}
public static readonly DependencyProperty MouseOverBackgroundProperty =
DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ButtonEx), new PropertyMetadata());
///
/// 鼠标按下背景颜色
///
public Brush MousePressedBackground
{
get { return (Brush)GetValue(MousePressedBackgroundProperty); }
set { SetValue(MousePressedBackgroundProperty, value); }
}
public static readonly DependencyProperty MousePressedBackgroundProperty =
DependencyProperty.Register("MousePressedBackground", typeof(Brush), typeof(ButtonEx), new PropertyMetadata());
///
/// SVG
///
public Geometry PathData
{
get
{
return (Geometry)GetValue(PathDataProperty);
}
set
{
SetValue(PathDataProperty, value);
}
}
// Using a DependencyProperty as the backing store for PathData. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PathDataProperty =
DependencyProperty.Register("PathData", typeof(Geometry), typeof(ButtonEx), new PropertyMetadata(new PathGeometry()));
public double PathWidth
{
get { return (double)GetValue(PathWidthProperty); }
set { SetValue(PathWidthProperty, value); }
}
// Using a DependencyProperty as the backing store for PathWidth. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PathWidthProperty =
DependencyProperty.Register("PathWidth", typeof(double), typeof(ButtonEx), new PropertyMetadata());
public double PathHeight
{
get { return (double)GetValue(PathHeightProperty); }
set { SetValue(PathHeightProperty, value); }
}
// Using a DependencyProperty as the backing store for PathHeight. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PathHeightProperty =
DependencyProperty.Register("PathHeight", typeof(double), typeof(ButtonEx), new PropertyMetadata());
}
public enum ButtonType
{
Normal,
Icon,
Text,
IconText,
Path,
Content,
}
新增 ButtonEx.xaml
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HL.SelfTicket.Controls">
wpf 自定义Button按钮
标签:try sch nts triggers override font tac shadow readonly
原文地址:https://www.cnblogs.com/zisai/p/11050710.html