上次在写button实现圆角的时候写了个支持按钮更换背景,支持滑动更换背景和不可用背景的样式。但是写的样式比较死,无法支持一套样式走天下。现在我跟该了下之前写的!
代码如下:
public class SunButton : Button
{
#region 属性
/// <summary>
/// 圆角
/// </summary>
public int BorderRadius
{
get { return (int)GetValue(BorderRadiusProperty); }
set { SetValue(BorderRadiusProperty, value); }
}
public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register("BorderRadius", typeof(int), typeof(SunButton),new FrameworkPropertyMetadata());
/// <summary>
/// 默认背景
/// </summary>
public string DefaultBackground
{
get { return (string)GetValue(DefaultBackgroundProperty); }
set { SetValue(DefaultBackgroundProperty, value); }
}
public static readonly DependencyProperty DefaultBackgroundProperty = DependencyProperty.Register("DefaultBackground", typeof(string), typeof(SunButton), new FrameworkPropertyMetadata());
/// <summary>
/// 不可用背景
/// </summary>
public string EnabledBackground
{
get { return (string)GetValue(EnabledBackgroundProperty); }
set { SetValue(EnabledBackgroundProperty, value); }
}
public static readonly DependencyProperty EnabledBackgroundProperty = DependencyProperty.Register("EnabledBackground", typeof(string), typeof(SunButt