using System;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Forms;
|
using System.Windows.Media;
|
using XCommon;
|
using XCommon.Log;
|
using Color = System.Windows.Media.Color;
|
using UserControl = System.Windows.Controls.UserControl;
|
|
namespace XHandler.View.ColorPicker
|
{
|
/// <summary>
|
/// 颜色表示按钮
|
/// </summary>
|
public partial class ColorPickerBtn : UserControl
|
{
|
#region 属性
|
#region RGB字符串值(255,255,0)
|
/// <summary>
|
/// RGB
|
/// </summary>
|
public static readonly DependencyProperty RGBProperty = DependencyProperty.Register("RGB", typeof(string), typeof(ColorPickerBtn),
|
new FrameworkPropertyMetadata((string)"", OnRGBChanged));
|
|
public string RGB
|
{
|
get { return (string)GetValue(RGBProperty); }
|
set { SetValue(RGBProperty, value); }
|
}
|
|
public static void OnRGBChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
{
|
ColorPickerBtn colorPickerBtn = (ColorPickerBtn)d;
|
|
// 颜色设置
|
colorPickerBtn.SetColor();
|
}
|
#endregion
|
#endregion
|
|
#region 事件
|
/// <summary>
|
/// 颜色改变事件
|
/// </summary>
|
public event EventHandler SelectedColorChangedEvent;
|
#endregion
|
|
#region 构造函数
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public ColorPickerBtn()
|
{
|
InitializeComponent();
|
}
|
#endregion
|
|
#region 初始化
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
// 颜色设置
|
SetColor();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
|
/// <summary>
|
/// 颜色设置
|
/// </summary>
|
public void SetColor()
|
{
|
btnShowColor.Background = new SolidColorBrush(ComUtility.RGBToColor(RGB));
|
}
|
#endregion
|
|
/// <summary>
|
/// 显示颜色拾取器
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnShowColor_Click(object sender, RoutedEventArgs e)
|
{
|
ColorPickerEx colorPickerEx = new ColorPickerEx();
|
colorPickerEx.ColorBrush = (SolidColorBrush)btnShowColor.Background;
|
colorPickerEx.ShowDialog();
|
|
if (colorPickerEx.DialogResult == true)
|
{
|
Color color = colorPickerEx.ColorBrush.Color;
|
//btnShowColor.Background = new SolidColorBrush(color);
|
RGB = $"{color.R},{color.G},{color.B}";
|
|
if (SelectedColorChangedEvent != null)
|
{
|
SelectedColorChangedEvent(this, EventArgs.Empty);
|
}
|
}
|
}
|
}
|
}
|