Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace TestZaMapu
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- TranslationFactorX = 0;
- TranslationFactorY = 0;
- isPanning = false;
- }
- private Point ptOldPosition;
- private bool isPanning;
- public static readonly DependencyProperty TranslateX =
- DependencyProperty.Register("TranslationFactorX", typeof(double), typeof(MainWindow));
- public static readonly DependencyProperty TranslateY =
- DependencyProperty.Register("TranslationFactorY", typeof(double), typeof(MainWindow));
- public double TranslationFactorX
- {
- get { return (double)GetValue(TranslateX); }
- set { SetValue(TranslateX, value); }
- }
- public double TranslationFactorY
- {
- get { return (double)GetValue(TranslateY); }
- set { SetValue(TranslateY, value); }
- }
- private void GlavniProzor_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonDown(e);
- if (isPanning)
- return;
- isPanning = this.CaptureMouse();
- ptOldPosition = e.GetPosition(this);
- }
- private void GlavniProzor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonUp(e);
- if (this.IsMouseCaptured)
- {
- this.ReleaseMouseCapture();
- isPanning = false;
- }
- }
- private void GlavniProzor_MouseMove(object sender, MouseEventArgs e)
- {
- base.OnMouseMove(e);
- if (isPanning)
- {
- Point ptNewPosition = e.GetPosition(this);
- if (ptNewPosition != ptOldPosition)
- {
- Vector direction = ptOldPosition - ptNewPosition;
- direction.X = TranslationFactorX - direction.X;
- direction.Y = TranslationFactorY - direction.Y;
- TranslationFactorX = direction.X;
- TranslationFactorY = direction.Y;
- ptOldPosition = ptNewPosition;
- }
- }
- }
- private void GlavniProzor_LostMouseCapture(object sender, MouseEventArgs e)
- {
- isPanning = false;
- this.OnLostMouseCapture(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement