using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
namespace BPA.UIControl
{
///
/// 双击转命令
///
public class DoubleClicker : ContentControl
{
///
/// 命令
///
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
"CommandParameter", typeof(object), typeof(DoubleClicker), new FrameworkPropertyMetadata(null));
///
/// 命令参数
///
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command", typeof(ICommand), typeof(DoubleClicker), new FrameworkPropertyMetadata(null));
///
/// 是否是双击区域
///
public static readonly DependencyProperty IsDoubleClickAreaProperty = DependencyProperty.RegisterAttached(
"IsDoubleClickArea", typeof(bool), typeof(DoubleClicker), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits));
///
/// 命令
///
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
///
/// 命令参数
///
public object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
///
/// 是否是双击区域
///
public static void SetIsDoubleClickArea(DependencyObject element, bool value)
{
element.SetValue(IsDoubleClickAreaProperty, value);
}
///
/// 是否是双击区域
///
public static bool GetIsDoubleClickArea(DependencyObject element)
{
return (bool)element.GetValue(IsDoubleClickAreaProperty);
}
///
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
if (Command != null && GetIsDoubleClickArea((DependencyObject)e.OriginalSource))
{
Command.Execute(CommandParameter);
}
}
}
}