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