Kaynağa Gözat

Implement MiddleMouseClick

Equbuxu 4 yıl önce
ebeveyn
işleme
a04cd7e32c

+ 2 - 4
PixiEditor/Views/UserControls/DrawingViewPort.xaml

@@ -15,15 +15,13 @@
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
         <converters:IntToViewportRectConverter x:Key="IntToViewportRectConverter" />
     </UserControl.Resources>
-    <vws:MainDrawingPanel x:Name="DrawingPanel"
-                          MiddleMouseClickedCommand="{Binding MiddleMouseClickedCommand, ElementName=uc}" 
-                          MiddleMouseClickedCommandParameter="{x:Type tools:MoveViewportTool}">
+    <vws:MainDrawingPanel x:Name="DrawingPanel">
         <i:Interaction.Triggers>
             <i:EventTrigger EventName="MouseMove">
                 <i:InvokeCommandAction Command="{Binding MouseMoveCommand, ElementName=uc}" />
             </i:EventTrigger>
             <i:EventTrigger EventName="MouseDown">
-                <i:InvokeCommandAction Command="{Binding MouseDownCommand, ElementName=uc}"/>
+                <i:InvokeCommandAction Command="{Binding InternalMouseDownCommand, ElementName=uc}"/>
             </i:EventTrigger>
         </i:Interaction.Triggers>
         <i:Interaction.Behaviors>

+ 19 - 6
PixiEditor/Views/UserControls/DrawingViewPort.xaml.cs

@@ -1,4 +1,6 @@
-using System.Windows;
+using PixiEditor.Helpers;
+using PixiEditor.Models.Tools.Tools;
+using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 
@@ -9,11 +11,6 @@ namespace PixiEditor.Views.UserControls
     /// </summary>
     public partial class DrawingViewPort : UserControl
     {
-        public DrawingViewPort()
-        {
-            InitializeComponent();
-        }
-
         public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
             DependencyProperty.Register(nameof(MiddleMouseClickedCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
 
@@ -67,5 +64,21 @@ namespace PixiEditor.Views.UserControls
             get => (bool)GetValue(GridLinesVisibleProperty);
             set => SetValue(GridLinesVisibleProperty, value);
         }
+
+        public RelayCommand InternalMouseDownCommand { get; private set; }
+
+        public DrawingViewPort()
+        {
+            InternalMouseDownCommand = new RelayCommand(ProcessMouseDown);
+            InitializeComponent();
+        }
+
+        private void ProcessMouseDown(object parameter)
+        {
+            if (Mouse.MiddleButton == MouseButtonState.Pressed && MiddleMouseClickedCommand.CanExecute(typeof(MoveViewportTool)))
+                MiddleMouseClickedCommand.Execute(typeof(MoveViewportTool));
+            if (MouseDownCommand.CanExecute(null))
+                MouseDownCommand.Execute(null);
+        }
     }
 }

+ 1 - 1
PixiEditor/Views/UserControls/MainDrawingPanel.xaml

@@ -13,7 +13,7 @@
     <Grid>
         <userc:Zoombox AdditionalContent="{Binding Item, ElementName=mainDrawingPanel}" />
         <xctk:Zoombox Cursor="{Binding Cursor}" Name="Zoombox" KeepContentInBounds="False" Visibility="Hidden"
-                  IsAnimated="False" MouseDown="Zoombox_MouseDown"
+                  IsAnimated="False"
                   CurrentViewChanged="Zoombox_CurrentViewChanged" DragModifiers="Blocked" ZoomModifiers="None">
             <i:Interaction.Triggers>
                 <i:EventTrigger EventName="MouseMove">

+ 0 - 26
PixiEditor/Views/UserControls/MainDrawingPanel.xaml.cs

@@ -26,12 +26,6 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty IsUsingZoomToolProperty =
             DependencyProperty.Register(nameof(IsUsingZoomTool), typeof(bool), typeof(MainDrawingPanel), new PropertyMetadata(false));
 
-        public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
-            DependencyProperty.Register(nameof(MiddleMouseClickedCommand), typeof(ICommand), typeof(MainDrawingPanel), new PropertyMetadata(default(ICommand)));
-
-        public static readonly DependencyProperty MiddleMouseClickedCommandParameterProperty =
-            DependencyProperty.Register(nameof(MiddleMouseClickedCommandParameter), typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(object)));
-
         public double MouseX
         {
             get => (double)GetValue(MouseXProperty);
@@ -62,18 +56,6 @@ namespace PixiEditor.Views
             set => SetValue(IsUsingZoomToolProperty, value);
         }
 
-        public ICommand MiddleMouseClickedCommand
-        {
-            get => (ICommand)GetValue(MiddleMouseClickedCommandProperty);
-            set => SetValue(MiddleMouseClickedCommandProperty, value);
-        }
-
-        public object MiddleMouseClickedCommandParameter
-        {
-            get => GetValue(MiddleMouseClickedCommandParameterProperty);
-            set => SetValue(MiddleMouseClickedCommandParameterProperty, value);
-        }
-
         public Point ClickPosition;
 
         public MainDrawingPanel()
@@ -94,14 +76,6 @@ namespace PixiEditor.Views
             ((IInputElement)sender).ReleaseMouseCapture();
         }
 
-        private void Zoombox_MouseDown(object sender, MouseButtonEventArgs e)
-        {
-            if (e.MiddleButton == MouseButtonState.Pressed &&
-                MiddleMouseClickedCommand.CanExecute(MiddleMouseClickedCommandParameter))
-            {
-                MiddleMouseClickedCommand.Execute(MiddleMouseClickedCommandParameter);
-            }
-        }
         private void Zoombox_CurrentViewChanged(object sender, ZoomboxViewChangedEventArgs e)
         {
             Zoombox.MinScale = 32 / ((FrameworkElement)Item).Width;