Ejemplo n.º 1
0
        private void ReOrderAllDragImage()
        {
            var orderDragImages = DragThumbs.OrderBy(c => c.ZIndex).ToList();

            for (int i = 0; i <= orderDragImages.Count() - 1; i++)
            {
                DragThumb di = orderDragImages[i];
                SetZIndex(di, i);
            }
        }
Ejemplo n.º 2
0
        public bool Save(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            XDocument xmlDoc = new XDocument();

            if (File.Exists(filePath))
            {
                xmlDoc = XDocument.Load(filePath);
            }
            else
            {
                xmlDoc = new XDocument();
            }

            XElement root = xmlDoc.Elements("root").FirstOrDefault();
            XElement drags = null, dbElem = null;

            if (root != null)
            {
                drags = root.Elements("FlowDesigns").FirstOrDefault();
                if (drags != null)
                {
                    drags.RemoveAll();
                }
                else
                {
                    drags = new XElement("FlowDesigns");

                    root.Add(drags);
                }
            }
            else
            {
                root  = new XElement("root");
                drags = new XElement("FlowDesigns");

                root.Add(drags);
            }

            foreach (DragThumb di in DragThumbs.OrderBy(c => c.ZIndex))
            {
                dbElem = new XElement(di.Name);

                dbElem.SetAttributeValue("Name", di.CtrlName);                                          //名称
                dbElem.SetAttributeValue("Position", new Point(Canvas.GetLeft(di), Canvas.GetTop(di))); //位置
                dbElem.SetAttributeValue("Size", new Size(di.Width, di.Height));                        //尺寸
                dbElem.SetAttributeValue("ItemType", di.CtrlType.ToString());                           //控件类型
                dbElem.SetAttributeValue("Background", di.Background.ToString());                       //背景色
                if (di.MonitorItem)
                {
                    dbElem.SetAttributeValue("Monitor", di.MonitorItem);                  //是否监控
                }
                if (di.ReadOnlyCanClick)
                {
                    dbElem.SetAttributeValue("ReadOnlyCanClick", di.ReadOnlyCanClick);                       //是否可以单击
                }
                if (di.BorderBrush != Brushes.White)
                {
                    dbElem.SetAttributeValue("BorderBrush", di.BorderBrush.ToString());  //边框色
                }

                if (di.CtrlType == EmFlowCtrlType.PolygonSharp)                                   //形状
                {
                    dbElem.SetAttributeValue("Shape", ((DragShape)di).BasicShapeType.ToString()); //形状类型
                }

                if (di.Source != null)
                {
                    string source  = di.Source.ToString().Replace("file:///", "");
                    string curPath = System.Environment.CurrentDirectory.Replace("\\", "/") + "/";
                    source = source.Replace(curPath, "");
                    dbElem.SetAttributeValue("Source", source); //图片路径
                }

                if (!string.IsNullOrEmpty(di.Text))
                {
                    dbElem.SetAttributeValue("Text", di.Text);                    //文本
                }
                dbElem.SetAttributeValue("Foreground", di.Foreground);            //文本颜色
                dbElem.SetAttributeValue("FontWeight", di.FontWeight.ToString()); //文本粗体
                dbElem.SetAttributeValue("FontSize", di.FontSize);                //字体大小

                drags.Add(dbElem);
            }

            Console.WriteLine(root.Value);

            try
            {
                //保存上面的修改  
                root.Save(filePath);

                bSaved = true;
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }