コード例 #1
0
        private DesignerItem DeserializeDesignerItem(XElement itemXML, Guid id, double OffsetX, double OffsetY)
        {
            JavaScriptSerializer serial = new JavaScriptSerializer();
            DesignerItem         item   = GetNewDesignerItem(id); //new DesignerItem(id);

            item.Width    = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture);
            item.Height   = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture);
            item.ParentID = new Guid(itemXML.Element("ParentID").Value);
            item.IsGroup  = Boolean.Parse(itemXML.Element("IsGroup").Value);
            Canvas.SetLeft(item, Double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + OffsetX);
            Canvas.SetTop(item, Double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + OffsetY);
            Canvas.SetZIndex(item, Int32.Parse(itemXML.Element("zIndex").Value));
            Object content = XamlReader.Load(XmlReader.Create(new StringReader(itemXML.Element("Content").Value)));

            item.SetContent(content);
            try
            {
                if (itemXML.Attribute("Tag") != null)
                {
                    item.Tag = itemXML.Attribute("Tag").Value;
                }
            }
            catch (Exception) { }
            return(item);
        }
コード例 #2
0
ファイル: DesignerCanvas.cs プロジェクト: schifflee/bcephal2
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                Object       content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    newItem = GetNewDesignerItem(Guid.NewGuid());
                    newItem.SetContent(content);

                    Point position = e.GetPosition(this);

                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    Canvas.SetZIndex(newItem, this.Children.Count);
                    this.Children.Add(newItem);
                    SetConnectorDecoratorTemplate(newItem);

                    //update selection
                    this.SelectionService.SelectItem(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }
コード例 #3
0
ファイル: DesignerCanvas.cs プロジェクト: schifflee/bcephal2
        protected DesignerItem DisplayBlock(UIElement block, object tag)
        {
            DesignerItem newItem = GetNewDesignerItem(Guid.NewGuid());

            newItem.SetContent(block);
            newItem.Tag           = tag;
            newItem.Renderer.Text = tag != null?tag.ToString() : newItem.Renderer.Text + newItem.ID;

            newItem.Edition += new DesignerItem.RoutedEventHandler(onEdit);

            Point p = Mouse.GetPosition(this);

            var n = Scale + 1;

            newItem.Width  = DesignerItem.BlockWidth * n;
            newItem.Height = DesignerItem.BlockHeight * n;

            if (point != null && point.HasValue)
            {
                DesignerCanvas.SetLeft(newItem, Math.Max(0, p.X));
                DesignerCanvas.SetTop(newItem, Math.Max(0, p.Y));
            }
            else
            {
                DesignerCanvas.SetLeft(newItem, Math.Max(0, p.X - newItem.Width / 2));
                DesignerCanvas.SetTop(newItem, Math.Max(0, p.Y - newItem.Height / 2));
            }

            Canvas.SetZIndex(newItem, this.Children.Count);
            this.Children.Add(newItem);
            SetConnectorDecoratorTemplate(newItem);

            this.SelectionService.SelectItem(newItem);
            newItem.Focus();
            return(newItem);
        }