Update ColorPicker.cs

This commit is contained in:
Mahdi Hosseini 2021-03-12 18:52:52 +03:30 committed by GitHub
parent 6dd5d4c5ff
commit 307150eeb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
@ -178,20 +178,30 @@ namespace HandyControl.Controls
#region Public Events
public static readonly RoutedEvent SelectedColorChangedEvent =
EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble,
typeof(EventHandler<FunctionEventArgs<Color>>), typeof(ColorPicker));
public event EventHandler<FunctionEventArgs<Color>> SelectedColorChanged
{
add => AddHandler(SelectedColorChangedEvent, value);
remove => RemoveHandler(SelectedColorChangedEvent, value);
}
/// <summary>
/// 颜色改变事件
/// </summary>
public static readonly RoutedEvent SelectedColorChangedEvent =
EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble,
public static readonly RoutedEvent ConfirmedEvent =
EventManager.RegisterRoutedEvent("Confirmed", RoutingStrategy.Bubble,
typeof(EventHandler<FunctionEventArgs<Color>>), typeof(ColorPicker));
/// <summary>
/// 颜色改变事件
/// </summary>
public event EventHandler<FunctionEventArgs<Color>> SelectedColorChanged
public event EventHandler<FunctionEventArgs<Color>> Confirmed
{
add => AddHandler(SelectedColorChangedEvent, value);
remove => RemoveHandler(SelectedColorChangedEvent, value);
add => AddHandler(ConfirmedEvent, value);
remove => RemoveHandler(ConfirmedEvent, value);
}
/// <summary>
@ -268,6 +278,10 @@ namespace HandyControl.Controls
}
ctl.UpdateStatus(v.Color);
ctl.SelectedBrushWithoutOpacity = new SolidColorBrush(Color.FromRgb(v.Color.R, v.Color.G, v.Color.B));
ctl.RaiseEvent(new FunctionEventArgs<Color>(SelectedColorChangedEvent, ctl)
{
Info = v.Color
});
}));
/// <summary>
@ -361,6 +375,8 @@ namespace HandyControl.Controls
_isLoaded = true;
}
};
cPicker = this;
}
public override void OnApplyTemplate()
@ -695,10 +711,14 @@ namespace HandyControl.Controls
}
private void ButtonConfirm_OnClick(object sender, RoutedEventArgs e)
=> RaiseEvent(new FunctionEventArgs<Color>(SelectedColorChangedEvent, this)
{
Info = SelectedBrush.Color
});
{
RaiseEvent(new FunctionEventArgs<Color>(ConfirmedEvent, this)
{
Info = SelectedBrush.Color
});
RaiseEvent(new RoutedEventArgs(CanceledEvent));
}
private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) => RaiseEvent(new RoutedEventArgs(CanceledEvent));
@ -731,6 +751,5 @@ namespace HandyControl.Controls
}
public bool CanDispose { get; } = true;
}
}