Skip to content

Activate Zoombox only when a ModifierKey is pressed #66

@sa-he

Description

@sa-he

In my current scenario the Zoombox control contains other custom user-controls that support drag&drop and other mouse-related features.

Therefore, I'd appreciate if the Zoombox activates it’s functionality only if e.g. the Control-key is pressed. The following code-snippet demonstrates my idea. OnMouseWheel also would need to respect ActivateOn accordingly..

What do you think of this idea?

  public ModifierKeys ActivateOn
   {
       get { return (ModifierKeys)GetValue(ActivateOnProperty); }
       set { SetValue(ActivateOnProperty, value); }
   }

   public static readonly DependencyProperty ActivateOnProperty = DependencyProperty.Register(nameof(ActivateOn), typeof(ModifierKeys), typeof(Zoombox), new PropertyMetadata(ModifierKeys.None));

   /// <inheritdoc />
   protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
   {
       if (e is null)
       {
           throw new ArgumentNullException(nameof(e));
       }

       this.position = e.GetPosition(this);
       if (ActivateOn == ModifierKeys.None || Keyboard.Modifiers.HasFlag(ActivateOn))
       {
           _ = this.CaptureMouse();
       }

       base.OnMouseLeftButtonDown(e);
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions