コード例 #1
0
        public static void SerializeToXML(CanvasLayer canvas, string filename)
        {
            try
            {
                //var fileStream = File.Create(filename);
                var elements = canvas.Visuals;
                //        using (var xmlWriter = XmlWriter.Create(filename))
                //        {
                var        xmlDoc = new XmlDocument();
                XmlElement root   = xmlDoc.CreateElement("Canvas");
                xmlDoc.AppendChild(root);

                var mySerializer = new XmlSerializer(typeof(Visual));
                foreach (var element in elements)
                {
                    XmlElement child = null;

                    var elemToSer = element as OxFigure;
                    if (elemToSer == null)
                    {
                        continue;
                    }
                    switch (elemToSer.Name)
                    {
                    case OxFigure.Shape.Point:
                    {
                        var elemAsPoint = elemToSer as OxPoint;
                        if (elemAsPoint == null)
                        {
                            continue;
                        }
                        child = xmlDoc.CreateElement("Point");
                        child.SetAttribute("X", value: elemAsPoint.X.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y", value: elemAsPoint.Y.ToString(CultureInfo.InvariantCulture));
                        child.InnerText = "Point";
                        break;
                    }

                    case OxFigure.Shape.Square:
                    {
                        var elemAsSquare = elemToSer as OxRectangle;
                        if (elemAsSquare == null)
                        {
                            continue;
                        }

                        child = xmlDoc.CreateElement("Square");
                        child.SetAttribute("SizeW", elemAsSquare.size.Width.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("SizeH", elemAsSquare.size.Height.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X", value: elemAsSquare.X.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y", value: elemAsSquare.Y.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X2", value: elemAsSquare.X2.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y2", value: elemAsSquare.Y2.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Color", value: elemAsSquare.XmlColor);
                        child.InnerText = "Square";
                        break;
                    }

                    case OxFigure.Shape.Ellispe:
                    {
                        var elemAsCircle = elemToSer as OxCircle;
                        if (elemAsCircle == null)
                        {
                            continue;
                        }

                        child = xmlDoc.CreateElement("Circle");
                        child.SetAttribute("SizeW", elemAsCircle.size.Width.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("SizeH", elemAsCircle.size.Height.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X", value: elemAsCircle.X.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y", value: elemAsCircle.Y.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Color", value: elemAsCircle.XmlColor);
                        child.InnerText = "Circle";
                        break;
                    }

                    case OxFigure.Shape.Rectangle:
                    {
                        var elemAsRect = elemToSer as OxRectangle;
                        if (elemAsRect == null)
                        {
                            continue;
                        }

                        child = xmlDoc.CreateElement("Rectangle");
                        child.SetAttribute("SizeW", elemAsRect.size.Width.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("SizeH", elemAsRect.size.Height.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X", value: elemAsRect.X.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y", value: elemAsRect.Y.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X2", value: elemAsRect.X2.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y2", value: elemAsRect.Y2.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Color", value: elemAsRect.XmlColor);
                        child.InnerText = "Rectangle";
                        break;
                    }

                    case OxFigure.Shape.Line:
                    {
                        var elemAsLine = elemToSer as OxLine;
                        if (elemAsLine == null)
                        {
                            continue;
                        }

                        child = xmlDoc.CreateElement("Line");
                        child.SetAttribute("X", value: elemAsLine.X.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y", value: elemAsLine.Y.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("X2", value: elemAsLine.X2.ToString(CultureInfo.InvariantCulture));
                        child.SetAttribute("Y2", value: elemAsLine.Y2.ToString(CultureInfo.InvariantCulture));
                        child.InnerText = "Line";
                        break;
                    }
                    }
                    if (child != null)
                    {
                        root.AppendChild(child);
                    }
                    xmlDoc.Save(filename);
                }
                //         }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 39 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.New_click);

            #line default
            #line hidden
                return;

            case 2:

            #line 41 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.open_click);

            #line default
            #line hidden
                return;

            case 3:
                this.save_btn = ((System.Windows.Controls.MenuItem)(target));

            #line 42 "..\..\..\MainWindow.xaml"
                this.save_btn.Click += new System.Windows.RoutedEventHandler(this.save_click);

            #line default
            #line hidden
                return;

            case 4:
                this.save_as_btn = ((System.Windows.Controls.MenuItem)(target));

            #line 43 "..\..\..\MainWindow.xaml"
                this.save_as_btn.Click += new System.Windows.RoutedEventHandler(this.save_as_click);

            #line default
            #line hidden
                return;

            case 5:

            #line 44 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.clear_click);

            #line default
            #line hidden
                return;

            case 6:

            #line 45 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.exit_click);

            #line default
            #line hidden
                return;

            case 7:

            #line 48 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.undo_click);

            #line default
            #line hidden
                return;

            case 8:

            #line 49 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.redo_click);

            #line default
            #line hidden
                return;

            case 9:

            #line 52 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.About_click);

            #line default
            #line hidden
                return;

            case 10:

            #line 53 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Help_click);

            #line default
            #line hidden
                return;

            case 11:
                this.coords = ((System.Windows.Controls.Primitives.StatusBar)(target));
                return;

            case 12:
                this.New = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 66 "..\..\..\MainWindow.xaml"
                this.New.Click += new System.Windows.RoutedEventHandler(this.New_click);

            #line default
            #line hidden
                return;

            case 13:
                this.Open = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 69 "..\..\..\MainWindow.xaml"
                this.Open.Click += new System.Windows.RoutedEventHandler(this.open_click);

            #line default
            #line hidden
                return;

            case 14:
                this.Save = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 72 "..\..\..\MainWindow.xaml"
                this.Save.Click += new System.Windows.RoutedEventHandler(this.save_click);

            #line default
            #line hidden
                return;

            case 15:
                this.SaveAs = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 75 "..\..\..\MainWindow.xaml"
                this.SaveAs.Click += new System.Windows.RoutedEventHandler(this.save_as_click);

            #line default
            #line hidden
                return;

            case 16:
                this.Undo = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 78 "..\..\..\MainWindow.xaml"
                this.Undo.Click += new System.Windows.RoutedEventHandler(this.undo_click);

            #line default
            #line hidden
                return;

            case 17:
                this.Redo = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 81 "..\..\..\MainWindow.xaml"
                this.Redo.Click += new System.Windows.RoutedEventHandler(this.redo_click);

            #line default
            #line hidden
                return;

            case 18:
                this.separator1 = ((System.Windows.Controls.Separator)(target));
                return;

            case 19:
                this.hand_btn = ((PhoenixControlLib.RadioToggleButton)(target));

            #line 85 "..\..\..\MainWindow.xaml"
                this.hand_btn.Click += new System.Windows.RoutedEventHandler(this.hand_click);

            #line default
            #line hidden
                return;

            case 20:

            #line 88 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.point_click);

            #line default
            #line hidden
                return;

            case 21:

            #line 91 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.line_click);

            #line default
            #line hidden
                return;

            case 22:

            #line 94 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.square_click);

            #line default
            #line hidden
                return;

            case 23:

            #line 97 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.rect_click);

            #line default
            #line hidden
                return;

            case 24:

            #line 100 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.triangle_click);

            #line default
            #line hidden
                return;

            case 25:

            #line 103 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.ellipse_click);

            #line default
            #line hidden
                return;

            case 26:

            #line 106 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.erase_click);

            #line default
            #line hidden
                return;

            case 27:

            #line 109 "..\..\..\MainWindow.xaml"
                ((PhoenixControlLib.RadioToggleButton)(target)).Click += new System.Windows.RoutedEventHandler(this.fill_click);

            #line default
            #line hidden
                return;

            case 28:
                this.setFigSize = ((System.Windows.Controls.ComboBox)(target));

            #line 112 "..\..\..\MainWindow.xaml"
                this.setFigSize.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.setFigSize_SelectionChanged);

            #line default
            #line hidden
                return;

            case 29:
                this.colorPick = ((Xceed.Wpf.Toolkit.ColorPicker)(target));

            #line 125 "..\..\..\MainWindow.xaml"
                this.colorPick.SelectedColorChanged += new System.Windows.RoutedPropertyChangedEventHandler <System.Windows.Media.Color>(this.colorPick_SelectedColorChanged);

            #line default
            #line hidden
                return;

            case 30:
                this.drawingSurface = ((WpfApplication2.Layers.CanvasLayer)(target));
                return;
            }
            this._contentLoaded = true;
        }
コード例 #3
0
        public static void DeserializeFromXML(string filename, ref CanvasLayer canvas)
        {
            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(filename);
                var root = xmlDoc.FirstChild;

                if (xmlDoc.DocumentElement != null)
                {
                    //foreach (var node in xmlDoc.DocumentElement.ChildNodes)
                    foreach (XmlNode node in root.ChildNodes)
                    {
                        if (node.Attributes != null)
                        {
                            XmlAttributeCollection attributes;
                            switch (node.Name)
                            {
                            case "Point":
                            {
                                Debug.WriteLine("1");
                                attributes = node.Attributes;
                                OxFigure figure = new OxPoint();
                                figure.Name = OxFigure.Shape.Point;
                                var point = new Point(Int32.Parse(attributes["X"].Value), Int32.Parse(attributes["Y"].Value));
                                DrawingLayer.GetInstance.DrawFigure(ref figure, point, true);
                                canvas.AddVisual(figure);

                                break;
                            }

                            case "Square":
                            {
                                attributes = node.Attributes;
                                OxFigure figure = new OxRectangle();
                                figure.Name = OxFigure.Shape.Square;
                                var point1 = new Point(Int32.Parse(attributes["X"].Value), Int32.Parse(attributes["Y"].Value));
                                figure.size  = new System.Windows.Size(Double.Parse(attributes["SizeW"].Value), Double.Parse(attributes["SizeH"].Value));
                                figure.Color = Colors.Black;
                                DrawingLayer.GetInstance.DrawFigure(ref figure, point1, false);
                                canvas.AddVisual(figure);
                                break;
                            }

                            case "Circle":
                            {
                                attributes = node.Attributes;
                                OxFigure figure = new OxCircle();
                                figure.Name = OxFigure.Shape.Rectangle;
                                var point1 = new Point(Int32.Parse(attributes["X"].Value), Int32.Parse(attributes["Y"].Value));
                                figure.size  = new System.Windows.Size(Double.Parse(attributes["SizeW"].Value), Double.Parse(attributes["SizeH"].Value));
                                figure.Color = Colors.Black;
                                DrawingLayer.GetInstance.DrawFigure(ref figure, point1, false);
                                canvas.AddVisual(figure);
                                break;
                            }

                            case "Rectangle":
                            {
                                attributes = node.Attributes;
                                OxFigure figure = new OxRectangle();
                                figure.Name = OxFigure.Shape.Rectangle;
                                var point1 = new Point(Int32.Parse(attributes["X"].Value), Int32.Parse(attributes["Y"].Value));
                                figure.size  = new System.Windows.Size(Double.Parse(attributes["SizeW"].Value), Double.Parse(attributes["SizeH"].Value));
                                figure.Color = Colors.Black;
                                DrawingLayer.GetInstance.DrawFigure(ref figure, point1, false);
                                canvas.AddVisual(figure);
                                break;
                            }

                            case "Line":
                            {
                                attributes = node.Attributes;
                                OxFigure figure = new OxLine();
                                figure.Name = OxFigure.Shape.Line;
                                var point1 = new Point(Int32.Parse(attributes["X"].Value), Int32.Parse(attributes["Y"].Value));
                                var point2 = new Point(Int32.Parse(attributes["X2"].Value), Int32.Parse(attributes["Y2"].Value));
                                DrawingLayer.GetInstance.DrawLine(ref figure, point1, point2);
                                figure.Color = Colors.Black;
                                DrawingLayer.GetInstance.DrawFigure(ref figure, point1, false);
                                canvas.AddVisual(figure);
                                break;
                            }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }