コード例 #1
0
        public List <DesignerContainer> DeserializeDesignerItems(XElement root)// 从xml文件解析图元
        {
            //CommandOpen.Run(CommManager, root);
            Dictionary <Guid, DesignerContainer> items = new Dictionary <Guid, DesignerContainer>();

            IEnumerable <XElement> itemsXml = root.Elements("DesignerContainers").Elements();

            foreach (XElement itemXml in itemsXml)
            {
                #region xml

                /*
                 * <DesignerElement Version="1.0" Type="Wss.Foundation.Controls.DesignerContainer, Wss.Foundation">
                 * <Name>换热器</Name>
                 * <Canvas.Left>522</Canvas.Left>
                 * <Canvas.Top>257</Canvas.Top>
                 * <Width>142</Width>
                 * <Height>200</Height>
                 * <Panel.ZIndex>20</Panel.ZIndex>
                 * <ItemOpacity>1</ItemOpacity>
                 * <LockDesign>False</LockDesign>
                 * <WindowTip>False</WindowTip>
                 * <NameVisible>True</NameVisible>
                 * <NamePosition></NamePosition>
                 * <Angle>0</Angle>
                 * <BaseContainer.ScaleX>1</BaseContainer.ScaleX>
                 * <BaseContainer.ScaleY>1</BaseContainer.ScaleY>
                 * <BaseContainer.ID>ba33c2e8-f1d9-4d37-9d54-4d7a4800d720</BaseContainer.ID>
                 * <BaseContainer.ParentID>00000000-0000-0000-0000-000000000000</BaseContainer.ParentID>
                 * <BaseContainer.IsGroup>False</BaseContainer.IsGroup>
                 * <DesignerElement Version="1.0" Type="Common.Package.HeatExchanger, Common.Package" />
                 * </DesignerElement>
                 */
                #endregion
                DesignerContainer item = DesignAttributeService.DeSerializFromXElement(itemXml) as DesignerContainer; // itemXml.ToDesignerContainer(); //从xml序列化成控件
                Add(item);                                                                                            //item.Content有值的
                if (!items.ContainsKey(item.ID))
                {
                    items.Add(item.ID, item);
                    PropertyInfo[] ps = item.Content.GetType().GetProperties();

                    item.IsHitTestVisible  = !(GetZIndex(item).Equals(int.MinValue));
                    item.Focusable         = item.IsHitTestVisible;
                    item.IsEnabled         = item.IsHitTestVisible;
                    item.IsSelected        = false;
                    item.PreviewMouseMove += Item_PreviewMouseMove;
                }
            }
            //InvalidateVisual();
            return(items.Values.ToList());
        }
コード例 #2
0
        //将List<DesignerContainer>转换为XElement节点
        public static XElement ToXElement(this IEnumerable <DesignerContainer> obj)
        {
            var result = new XElement("DesignerContainers");

            if (obj == null)
            {
                return(result);
            }
            foreach (var item in obj)
            {
                result.Add(DesignAttributeService.SerializToXElement(item));
            }
            return(result);
        }
コード例 #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                _dragStartPoint = null;
            }

            if (!_dragStartPoint.HasValue)
            {
                return;
            }
            var di = Content as DesignerItem;

            if (di != null)
            {
                var dcontainer = new DesignerContainer();
                dcontainer.Content = di;
                var panel = VisualTreeHelper.GetParent(this) as WrapPanel;

                var dataObject = new DragObject();
                dataObject.Xaml = DesignAttributeService.SerializToXElement(dcontainer).ToString();

                if (panel != null)
                {
                    // desired size for DesignerCanvas is the stretched Toolbox Item size
                    var scale = 1.0;
                    dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                #region  用
                //var dcontainer = new DesignerContainer();
                //dcontainer.Content = item;

                //WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                //DragObject dataObject = new DragObject();
                //dataObject.Xaml= System.Windows.Markup.XamlWriter.Save(item);//dataObject.Xaml = DesignAttributeService.SerializToXElement(di).ToString();
                //if (panel != null)
                //{
                //    var scale = 1.0;
                //    dataObject.DesiredSize = new Size(panel.ItemWidth*scale, panel.ItemHeight*scale);
                //}

                ////DragDrop.DoDragDrop(this, di, DragDropEffects.Copy);
                //DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                #endregion
            }
            e.Handled = true;
        }
コード例 #4
0
        //将XElement节点转换为一组DesignerItem
        public static List <DesignerContainer> ToDesignerContainers(this XElement xElement)
        {
            var result = new List <DesignerContainer>();

            if (xElement == null)
            {
                return(result);
            }
            var items = xElement.Elements();

            result.AddRange(items.Select(item =>
                                         DesignAttributeService.DeSerializFromXElement(item) as DesignerContainer
                                         ).Where(ditem => ditem != null));
            return(result);
        }
コード例 #5
0
 //将XElement节点转换为DesignerItem实例,对于结构不符合的节点,将返回null
 public static DesignerContainer ToDesignerContainer(this XElement xElement)
 {
     return(DesignAttributeService.DeSerializFromXElement(xElement) as DesignerContainer);
 }
コード例 #6
0
        //显示属性窗口
        public void ShowProView(bool isShowContainerPro)
        {
            if (_designerCanvas == null || _designerCanvas.SelectionService == null)
            {
                return;
            }
            var title = Template.FindName("title", this) as Label;

            if (title != null)
            {
                title.MouseLeftButtonDown  += title_MouseLeftButtonDown;
                title.MouseLeftButtonUp    += title_MouseLeftButtonUp;
                title.MouseRightButtonDown += title_MouseRightButtonDown;
            }
            if (_designerCanvas.SelectionService.SelectedDesignerContainer == null || _designerCanvas.SelectionService.SelectedDesignerContainer.Count <= 0)
            {
                return;
            }
            //画布上有选择的控件
            List <DesignerContainer> listCtn = _designerCanvas.SelectionService.SelectedDesignerContainer.OfType <DesignerContainer>().Where(x => x.ParentID == Guid.Empty).ToList();

            if (listCtn.Count != 1)
            {
                this.Visibility = Visibility.Collapsed; return;
            }

            ListView lvName  = Template.FindName("lvName", this) as ListView;
            ListView lvValue = Template.FindName("lvValue", this) as ListView;//找到属性窗口的listView

            lvName.Items.Clear(); lvValue.Items.Clear();

            DependencyObject dobj = listCtn.First();                                                //显示第一个被选择的控件的属性
            var pros = DesignAttributeService.GetDesignPropertys(dobj).OrderBy(o => o.DisplayName); //获取属性列表

            foreach (IDesignProperty p in pros)
            {
                if (isShowContainerPro)
                {
                    if (p.Owner.ToString().Contains("DesignerContainer"))
                    {
                        continue;
                    }
                }

                FrameworkElement   ctr;
                DependencyProperty ctrpp = TextBox.TextProperty;
                if (p.Editer != null)
                {
                    PropertyEditerButton bt = new PropertyEditerButton(p.Editer);
                    ctr        = bt;
                    bt.Content = "编 辑";
                    ctrpp      = PropertyEditerButton._property;
                }
                else
                {
                    #region 根据属性的类型,设定属性窗口该给什么控件
                    if (p.Descriptor != null)
                    {
                        if (p.Descriptor.PropertyType == typeof(bool))
                        {
                            ctr   = new CheckBox();
                            ctrpp = ToggleButton.IsCheckedProperty;
                        }
                        else if (p.Descriptor.PropertyType == typeof(Brush))
                        {
                            TextBox tb = new TextBox();
                            tb.MouseDoubleClick += tb_MouseDoubleClick;//显示颜色面板
                            ctr   = tb;
                            ctrpp = TextBox.TextProperty;
                        }
                        else if (p.Descriptor.PropertyType == typeof(Point))//坐标
                        {
                            TextBox tb = new TextBox();
                            tb.PreviewMouseRightButtonDown += tb_PreviewMouseRightButtonDown;
                            tb.MouseMove          += tb_MouseMove1;
                            tb.MouseRightButtonUp += tb_MouseRightButtonUp;
                            ctr = tb;
                        }
                        else
                        {
                            ctr = new TextBox();
                            if (p.DisplayName.Equals("名称"))
                            {
                                p.Binding.ValidationRules.Add(new NameRule());
                            }
                        }
                    }
                    else
                    {
                        ctr = new TextBox();
                        if (p.DisplayName.Equals("名称"))
                        {
                            p.Binding.ValidationRules.Add(new NameRule());
                        }
                    }
                    #endregion
                }
                ctr.IsEnabled = !p.ReadOnly;
                ctr.SetBinding(ctrpp, p.Binding);

                AddProItem(p.DisplayName, ctr);
            }
            Visibility = Visibility.Visible;
        }