Skip to content

Commit

Permalink
Use dependency properties for gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouterdek committed Nov 6, 2020
1 parent 83a42db commit 18c512d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
15 changes: 12 additions & 3 deletions NodeNetwork/Views/Controls/DragCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class DragCanvas : Canvas
/// </summary>
public Point DragOffset
{
get { return (Point)GetValue(DragOffsetProperty); }
set { SetValue(DragOffsetProperty, value); }
get => (Point)GetValue(DragOffsetProperty);
set => SetValue(DragOffsetProperty, value);
}

private static void DragOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down Expand Up @@ -60,10 +60,19 @@ private static void DragOffsetChanged(DependencyObject d, DependencyPropertyChan

public bool IsDraggingEnabled { get; set; } = true;

#region StartDragGesture
public static readonly DependencyProperty StartDragGestureProperty = DependencyProperty.Register(nameof(StartDragGesture),
typeof(MouseGesture), typeof(DragCanvas), new PropertyMetadata(new MouseGesture(MouseAction.LeftClick)));

/// <summary>
/// This mouse gesture starts a drag on the canvas. Left click by default.
/// </summary>
public MouseGesture StartDragGesture { get; set; } = new MouseGesture(MouseAction.LeftClick);
public MouseGesture StartDragGesture
{
get => (MouseGesture)GetValue(StartDragGestureProperty);
set => SetValue(StartDragGestureProperty, value);
}
#endregion

/// <summary>
/// Used when the mousebutton is down to check if the initial click was in this element.
Expand Down
22 changes: 20 additions & 2 deletions NodeNetwork/Views/NetworkView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,33 @@ public Brush NetworkBackground
/// </example>
public IInputElement CanvasOriginElement => contentContainer;

#region StartCutGesture
public static readonly DependencyProperty StartCutGestureProperty = DependencyProperty.Register(nameof(StartCutGesture),
typeof(MouseGesture), typeof(NetworkView), new PropertyMetadata(new MouseGesture(MouseAction.RightClick)));

/// <summary>
/// This mouse gesture starts a cut, making the cutline visible. Right click by default.
/// </summary>
public MouseGesture StartCutGesture { get; set; } = new MouseGesture(MouseAction.RightClick);
public MouseGesture StartCutGesture
{
get => (MouseGesture)GetValue(StartCutGestureProperty);
set => SetValue(StartCutGestureProperty, value);
}
#endregion

#region StartSelectionRectangleGesture
public static readonly DependencyProperty StartSelectionRectangleGestureProperty = DependencyProperty.Register(nameof(StartSelectionRectangleGesture),
typeof(MouseGesture), typeof(NetworkView), new PropertyMetadata(new MouseGesture(MouseAction.LeftClick, ModifierKeys.Shift)));

/// <summary>
/// This mouse gesture starts a selection, making the selection rectangle visible. Left click + Shift by default.
/// </summary>
public MouseGesture StartSelectionRectangleGesture { get; set; } = new MouseGesture(MouseAction.LeftClick, ModifierKeys.Shift);
public MouseGesture StartSelectionRectangleGesture
{
get => (MouseGesture)GetValue(StartSelectionRectangleGestureProperty);
set => SetValue(StartSelectionRectangleGestureProperty, value);
}
#endregion

public NetworkView()
{
Expand Down

0 comments on commit 18c512d

Please sign in to comment.