private void btnAccept_Click(object sender, RoutedEventArgs e) { var grd = new Viewbox(); MapCanvas.Children.Remove(poly); grd.Child = (poly); var miny = poly.Points.Min(_ => _.Y); var minx = poly.Points.Min(_ => _.X); Canvas.SetTop(grd, miny); Canvas.SetLeft(grd, minx); PointCollection pc = new PointCollection(); for (int index = 0; index < poly.Points.Count; index++) { var point = poly.Points[index]; point.Y = point.Y - miny; point.X = point.X - minx; pc.Add(point); } poly.Points = pc; poly.Margin = new Thickness(0); poly.VerticalAlignment = VerticalAlignment.Stretch; poly.HorizontalAlignment = HorizontalAlignment.Stretch; Designer designer = (Designer)App.Current.MainWindow; designer.MapCanvas.Children.Add(grd); ShapeHandler.SelectedImage = grd; ShapeHandler.InitImageHandlers(ref grd); }
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); } } } }; }