source: trunk/CrypPlugins/WorkspaceManager/View/VisualComponents/ImageWrapper.xaml.cs @ 1847

Last change on this file since 1847 was 1847, checked in by kopal, 11 years ago
  • added support for serializing/deserializing pictures into model files
File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using System.Windows.Controls;
7using System.Windows.Data;
8using System.Windows.Documents;
9using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
12using System.Windows.Navigation;
13using System.Windows.Shapes;
14using WorkspaceManager.Model;
15
16namespace WorkspaceManager.View.VisualComponents
17{
18    /// <summary>
19    /// Interaction logic for ImageWrapper.xaml
20    /// </summary>
21    public partial class ImageWrapper : UserControl
22    {
23        public Image Image { get; set; }
24        public Point Position { get; set; }
25        private Point previousDragPoint = new Point();
26        private ImageModel model = null;
27
28        public ImageWrapper(ImageModel model, Point point)
29        {
30            this.Image = model.getImage();
31            this.Position = point;
32            model.Position = point;
33            InitializeComponent();
34            this.MouseMove += new MouseEventHandler(ImageWrapper_MouseMove);
35            this.MouseLeftButtonDown +=new MouseButtonEventHandler(ImageWrapper_MouseLeftButtonDown);
36            this.RenderTransform = new TranslateTransform(Position.X, Position.Y);
37            this.root.Children.Add(Image);
38            this.model = model;
39        }
40
41        void ImageWrapper_MouseMove(object sender, MouseEventArgs e)
42        {
43            if (e.LeftButton == MouseButtonState.Pressed)
44            {
45                Point p = new Point(Mouse.GetPosition(this.Parent as Panel).X - previousDragPoint.X, (Mouse.GetPosition(this.Parent as Panel).Y - previousDragPoint.Y));
46                (this.RenderTransform as TranslateTransform).X = p.X;
47                (this.RenderTransform as TranslateTransform).Y = p.Y;
48                this.model.Position = p;
49            }
50        }
51
52        void ImageWrapper_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
53        {
54            this.previousDragPoint = Mouse.GetPosition(this); 
55        }
56
57        /*private Image makeImage(Uri imgUri)
58        {
59            try
60            {
61                Image img = new Image();
62                img.Source = new BitmapImage(imgUri);
63                return img;
64            }
65            catch (Exception e)
66            {
67                Console.Out.WriteLine(e.ToString());
68            }
69            return null;
70        }*/
71
72        public ImageWrapper()
73        {
74            InitializeComponent();
75        }
76    }
77}
Note: See TracBrowser for help on using the repository browser.