示例#1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     propertyGrid1.CommandsVisibleIfAvailable = true;
     host.Child = propertyGrid1;
     grid1.Children.Add(host);
     shapeHelper   = new ShapeHelper(canvas);
     polygonHelper = new PolygonHelper(canvas);
     saveNLoad     = new SaveNLoad(canvas);
 }
示例#2
0
        public void load()
        {
            try
            {
                shapeHelper   = new ShapeHelper(canvas);
                polygonHelper = new PolygonHelper(canvas);
                canvas.Children.Clear();
                OpenFileDialog Fd = new OpenFileDialog();
                Fd.ShowDialog();
                string LoadedFileName = Fd.FileName;

                //Load the file
                FileStream Fs = new FileStream(@LoadedFileName, FileMode.Open);

                canvas.Children.Clear();
                Canvas      newCanvas = System.Windows.Markup.XamlReader.Load(Fs) as Canvas;
                UIElement[] children  = new UIElement[newCanvas.Children.Capacity];
                newCanvas.Children.CopyTo(children, 0);
                foreach (UIElement child in children)
                {
                    if (child != null)
                    {
                        newCanvas.Children.Remove(child);
                        canvas.Children.Add(child);
                        if (child is Rectangle || child is Ellipse)
                        {
                            child.MouseLeftButtonDown  += shapeHelper.getPosition;
                            child.MouseRightButtonDown += shapeHelper.select;
                        }
                        else if (child is Polygon)
                        {
                            child.MouseLeftButtonDown  += polygonHelper.getPosition;
                            child.MouseRightButtonDown += polygonHelper.select;
                        }
                    }
                }



                Fs.Close();
            }
            catch { }
        }