Beispiel #1
0
        private void MenuItem_Open(object sender, RoutedEventArgs e)
        {
            var fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var content      = File.ReadAllText(fileDialog.FileName);
                var stringReader = new StringReader(content);
                var xmlReader    = XmlReader.Create(stringReader);
                MapCanvas = (Canvas)XamlReader.Load(xmlReader);
                CanvasHandler.InitCanvasHandlers();
            }
        }
Beispiel #2
0
        public Designer()
        {
            InitializeComponent();

            CanvasHandler.InitCanvasHandlers();

            Closing += (sender, args) => { Settings.Default.Save(); };

            PreviewKeyDown += (sender, e) =>
            {
                if (BaseHandler.ObjectSelected)
                {
                    //-- #######################################
                    //-- Copy
                    //-- #######################################
                    if (e.Key == Key.C && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        if (ImageHandler.SelectedImage != null)
                        {
                            var img         = ImageHandler.SelectedImage;
                            var savedObject = XamlWriter.Save(img);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Canvas)XamlReader.Load(xmlReader);
                        }
                        if (ShapeHandler.SelectedImage != null)
                        {
                            var img         = ShapeHandler.SelectedImage;
                            var savedObject = XamlWriter.Save(img);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Viewbox)XamlReader.Load(xmlReader);
                        }
                    }

                    //-- #######################################
                    //-- Paste
                    //-- #######################################
                    if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        var canvas = CopyTarget as Canvas;
                        if (canvas != null)
                        {
                            ImageHandler.AddImageToCanvas(ref canvas);

                            var position = Mouse.GetPosition(MapCanvas);
                            Canvas.SetTop(CopyTarget, position.Y);
                            Canvas.SetLeft(CopyTarget, position.X);
                            ImageHandler.SelectedImage = canvas;
                            SelectionFilter.ChangeFilters(CopyTarget);

                            var savedObject = XamlWriter.Save(CopyTarget);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Canvas)XamlReader.Load(xmlReader);
                        }
                        var grid = CopyTarget as Viewbox;
                        if (grid != null)
                        {
                            ShapeHandler.AddImageToCanvas(ref grid);

                            var position = Mouse.GetPosition(MapCanvas);
                            Canvas.SetTop(CopyTarget, position.Y);
                            Canvas.SetLeft(CopyTarget, position.X);
                            ShapeHandler.SelectedImage = grid;
                            SelectionFilter.ChangeFilters(CopyTarget);

                            var savedObject = XamlWriter.Save(CopyTarget);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Viewbox)XamlReader.Load(xmlReader);
                        }
                    }
                    //-- #######################################
                    //-- Delete
                    //-- #######################################
                    if (e.Key == Key.Delete)
                    {
                        if (ImageHandler.SelectedImage != null)
                        {
                            MapCanvas.Children.Remove(ImageHandler.SelectedImage);
                        }

                        if (ShapeHandler.SelectedImage != null)
                        {
                            MapCanvas.Children.Remove(ShapeHandler.SelectedImage);
                        }
                    }
                }
            };
        }