Advertisement
Guest User

Code behind

a guest
Oct 14th, 2015
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace TestZaMapu
  17. {
  18.     /// <summary>
  19.     /// Interaction logic for MainWindow.xaml
  20.     /// </summary>
  21.     public partial class MainWindow : Window
  22.     {
  23.         public MainWindow()
  24.         {
  25.             InitializeComponent();
  26.  
  27.             TranslationFactorX = 0;
  28.             TranslationFactorY = 0;
  29.             isPanning = false;
  30.  
  31.         }
  32.  
  33.         private Point ptOldPosition;
  34.         private bool isPanning;
  35.  
  36.         public static readonly DependencyProperty TranslateX =
  37.             DependencyProperty.Register("TranslationFactorX", typeof(double), typeof(MainWindow));
  38.  
  39.         public static readonly DependencyProperty TranslateY =
  40.             DependencyProperty.Register("TranslationFactorY", typeof(double), typeof(MainWindow));
  41.  
  42.         public double TranslationFactorX
  43.         {
  44.             get { return (double)GetValue(TranslateX); }
  45.             set { SetValue(TranslateX, value); }
  46.         }
  47.  
  48.         public double TranslationFactorY
  49.         {
  50.             get { return (double)GetValue(TranslateY); }
  51.             set { SetValue(TranslateY, value); }
  52.         }
  53.  
  54.         private void GlavniProzor_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  55.         {
  56.             base.OnMouseLeftButtonDown(e);
  57.             if (isPanning)
  58.                 return;
  59.             isPanning = this.CaptureMouse();
  60.             ptOldPosition = e.GetPosition(this);
  61.         }
  62.  
  63.         private void GlavniProzor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  64.         {
  65.             base.OnMouseLeftButtonUp(e);
  66.  
  67.             if (this.IsMouseCaptured)
  68.             {
  69.                 this.ReleaseMouseCapture();
  70.                 isPanning = false;
  71.             }
  72.         }
  73.  
  74.         private void GlavniProzor_MouseMove(object sender, MouseEventArgs e)
  75.         {
  76.             base.OnMouseMove(e);
  77.  
  78.             if (isPanning)
  79.             {
  80.                 Point ptNewPosition = e.GetPosition(this);
  81.  
  82.                 if (ptNewPosition != ptOldPosition)
  83.                 {
  84.                     Vector direction = ptOldPosition - ptNewPosition;
  85.  
  86.                     direction.X = TranslationFactorX - direction.X;
  87.                     direction.Y = TranslationFactorY - direction.Y;
  88.  
  89.                     TranslationFactorX = direction.X;
  90.                     TranslationFactorY = direction.Y;
  91.  
  92.                     ptOldPosition = ptNewPosition;
  93.                 }
  94.             }
  95.         }
  96.  
  97.         private void GlavniProzor_LostMouseCapture(object sender, MouseEventArgs e)
  98.         {
  99.             isPanning = false;
  100.             this.OnLostMouseCapture(e);
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement