110,537
社区成员
发帖
与我相关
我的任务
分享
public class CheckBox360 : CheckBox
{
public static readonly DependencyProperty ContentOnProperty = DependencyProperty.Register("ContentOn", typeof(string), typeof(CheckBox360), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty ContentOffProperty = DependencyProperty.Register("ContentOff", typeof(string), typeof(CheckBox360), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty ButtonBackgroundProperty = DependencyProperty.Register("ButtonBackground", typeof(Brush), typeof(CheckBox360), new PropertyMetadata(Brushes.White));
public static readonly DependencyProperty ButtonCenterBorderProperty = DependencyProperty.Register("ButtonCenterBorder", typeof(Brush), typeof(CheckBox360), new PropertyMetadata(Brushes.Gray));
/// <summary>
/// On 内容
/// </summary>
public string ContentOn
{
get { return (string)GetValue(ContentOnProperty); }
set { SetValue(ContentOnProperty, value); }
}
/// <summary>
/// off 内容
/// </summary>
public string ContentOff
{
get { return (string)GetValue(ContentOffProperty); }
set { SetValue(ContentOffProperty, value); }
}
/// <summary>
/// 圆饼按钮颜色
/// </summary>
public Brush ButtonBackground
{
get { return (Brush)GetValue(ButtonBackgroundProperty); }
set { SetValue(ButtonBackgroundProperty, value); }
}
/// <summary>
/// 圆饼按钮中间Border颜色
/// </summary>
public Brush ButtonCenterBorder
{
get { return (Brush)GetValue(ButtonCenterBorderProperty); }
set { SetValue(ButtonCenterBorderProperty, value); }
}
public CheckBox360()
{
Loaded += (sender, args) =>
{
try
{
this.Resources.Source = new Uri("DialogEx;Component/Controls/CheckBox360.xaml", UriKind.RelativeOrAbsolute);
}
catch
{
throw new Exception("未找到:DialogEx;Component/Controls/CheckBox360.xaml");
}
this.Resources["BtnBack"] = (Color)ColorConverter.ConvertFromString(ButtonBackground.ToString());
this.Resources["BtnCenterBorderBack"] = (Color)ColorConverter.ConvertFromString(ButtonCenterBorder.ToString());
this.Resources["CheckBoxOnText"] = ContentOn;
this.Resources["CheckBoxOFFText"] = ContentOff;
this.Style = this.Resources["CheckBoxStyle"] as Style;
};
}
}
public class CheckBox360 : CheckBox
{
public static readonly DependencyProperty ContentOnProperty = DependencyProperty.Register("ContentOn", typeof(string), typeof(CheckBox360), new PropertyMetadata(string.Empty, PropertyChanged));
public static readonly DependencyProperty ContentOffProperty = DependencyProperty.Register("ContentOff", typeof(string), typeof(CheckBox360), new PropertyMetadata(string.Empty, PropertyChanged));
public static readonly DependencyProperty ButtonBackgroundProperty = DependencyProperty.Register("ButtonBackground", typeof(Brush), typeof(CheckBox360), new PropertyMetadata(Brushes.White, PropertyChanged));
public static readonly DependencyProperty ButtonCenterBorderProperty = DependencyProperty.Register("ButtonCenterBorder", typeof(Brush), typeof(CheckBox360), new PropertyMetadata(Brushes.Gray, PropertyChanged));
/// <summary>
/// On 内容
/// </summary>
public string ContentOn
{
get { return (string)GetValue(ContentOnProperty); }
set { SetValue(ContentOnProperty, value);}
}
/// <summary>
/// off 内容
/// </summary>
public string ContentOff
{
get { return (string)GetValue(ContentOffProperty); }
set { SetValue(ContentOffProperty, value);}
}
/// <summary>
/// 圆饼按钮颜色
/// </summary>
public Brush ButtonBackground
{
get { return (Brush)GetValue(ButtonBackgroundProperty); }
set { SetValue(ButtonBackgroundProperty, value);}
}
/// <summary>
/// 圆饼按钮中间Border颜色
/// </summary>
public Brush ButtonCenterBorder
{
get { return (Brush)GetValue(ButtonCenterBorderProperty); }
set { SetValue(ButtonCenterBorderProperty, value); }
}
private void ValueChanged()
{
this.Resources["BtnBack"] = (Color)ColorConverter.ConvertFromString(ButtonBackground.ToString());
this.Resources["BtnCenterBorderBack"] = (Color)ColorConverter.ConvertFromString(ButtonCenterBorder.ToString());
this.Resources["CheckBoxOnText"] = ContentOn;
this.Resources["CheckBoxOFFText"] = ContentOff;
this.Style = this.Resources["CheckBoxStyle"] as Style;
}
public CheckBox360()
{
// Loaded += (sender, args) =>
{
try
{
this.Resources.Source = new Uri("WpfTest;Component/CheckBox360.xaml", UriKind.RelativeOrAbsolute);
}
catch
{
throw new Exception("未找到:WpfTest;Component/CheckBox360.xaml");
}
};
}
//属性改变
static void PropertyChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs e)
{
CheckBox360 control = (CheckBox360)dobj;
control.Resources["BtnBack"] = (Color)ColorConverter.ConvertFromString(control.ButtonBackground.ToString());
control.Resources["BtnCenterBorderBack"] = (Color)ColorConverter.ConvertFromString(control.ButtonCenterBorder.ToString());
control.Resources["CheckBoxOnText"] = control.ContentOn;
control.Resources["CheckBoxOFFText"] = control.ContentOff;
control.Style = control.Resources["CheckBoxStyle"] as Style;
//String.Format("PropertyChanged - 属性:{0} 新值:{1} 旧值:{2}", e.Property.Name, e.NewValue, e.OldValue);
}
}