Ejemplo n.º 1
0
        public DesignerItem AddDesignerItem(FrameworkElement item, Point position, Size?size, int layer = 0)
        {
            DesignerItem newItem = new DesignerItem();

            newItem.Content = item;
            newItem.Layer   = layer;
            if (size.HasValue)
            {
                newItem.Width  = size.Value.Width;
                newItem.Height = size.Value.Height;
            }

            DesignerCanvas.SetLeft(newItem, position.X);
            DesignerCanvas.SetTop(newItem, position.Y);

            //Canvas.SetZIndex(newItem, this.Children.Count);
            newItem.ZIndex = this.Children.Count;

            this.Children.Add(newItem);
            SetConnectorDecoratorTemplate(newItem);

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

            raiseDesignerItemAdded(item, newItem);

            updateVisibleDesigneritems();

            return(newItem);
        }
Ejemplo n.º 2
0
        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         = new DesignerItem();
                    newItem.Content = 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();
                    if (newItem.Content is Grid)
                    {
                        // newItem.Visibility = Visibility.Hidden;

                        Grid hijo = (Grid)newItem.Content;
                        foreach (UIElement item in hijo.Children)
                        {
                            item.SetValue(UIElement.VisibilityProperty, Visibility.Visible);
                        }

                        newItem.Content = hijo;
                        //  DesignerItem contenido = (DesignerItem)newItem.Content;
                        //   contenido.Focusable = true;
                    }
                }

                e.Handled = true;
            }
        }
Ejemplo n.º 3
0
        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         = new DesignerItem(dragObject.Tag);
                    newItem.Content = content;

                    var temp = newItem as ContentControl;
                    var abc  = temp.Content as TextBox;

                    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);

                    EnsureComponentUniqueName(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }
Ejemplo n.º 4
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            Console.WriteLine("Dropped");
            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         = new DesignerItem();
                    newItem.Content = content;

                    newItem.primaryField   = (Window.GetWindow(this) as Window1).tbComponentName.Text;
                    newItem.secondaryField = (Window.GetWindow(this) as Window1).tbComponentDesc.Text;

                    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;
                Console.WriteLine("handled creation");
            }
        }
Ejemplo n.º 5
0
        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)
                {
                    itemCounter = this.Children.OfType <DesignerItem>().Where(x => x.Tag.ToString() == dragObject.Class).Count();

                    newItem                   = new DesignerItem(Guid.NewGuid(), dragObject.Class, ++itemCounter);
                    newItem.Content           = content;
                    newItem.MouseDoubleClick += DesignerItem_MouseDoubleClick;

                    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;
            }
        }
Ejemplo n.º 6
0
 protected override void OnDrop(DragEventArgs e)
 {
     base.OnDrop(e);
     if (!String.IsNullOrEmpty(name))
     {
         node.comboData = ListData;
         DesignerItem newItem = node.addNode(name, nodeFileName);
         if (newItem.ItemType == "Target")
         {
             bool hasExist = false;
             for (int i = 0; i < targetPanel.Children.Count; ++i)
             {
                 DesignerItem temp = targetPanel.Children[i] as DesignerItem;
                 if (newItem.IDName.Equals(temp.IDName))
                 {
                     hasExist = true;
                     break;
                 }
             }
             if (!hasExist)
             {
                 this.targetPanel.Children.Add(newItem);
                 int    id    = ListData.Count - 1;
                 string value = id.ToString();
                 ListData.Add(new ComboData {
                     Id = id, Value = value
                 });
                 AddTriggerItem(newItem.ItemType, newItem);
             }
         }
         else
         {
             Point position = e.GetPosition(this);
             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);
             AddTriggerItem(newItem.ItemType, newItem);
             newItem.Focus();
         }
         e.Handled = true;
     }
 }
Ejemplo n.º 7
0
        //Adding and Removing DesignerItem On Collection Changed
        private void OnElementsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (ElementVM newItem in e.NewItems)
                {
                    DesignerItem NewDesignerItem = new DesignerItem();
                    NewDesignerItem.DataContext = newItem;
                    this.Children.Add(NewDesignerItem);
                    NewDesignerItem.ActivateConnectors();
                    NewDesignerItem.Focus();
                    SelectionService.SelectItem(NewDesignerItem);
                    Canvas.SetZIndex(NewDesignerItem, this.Children.Count);
                }
            }

            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (ElementVM removedItem in e.OldItems)
                {
                    DesignerItem     ToRemove   = GetDesignerItemByGuid(removedItem.ID);
                    Control          cd         = ToRemove.Template.FindName("PART_ConnectorDecorator", ToRemove) as Control;
                    List <Connector> connectors = new List <Connector>();
                    GetConnectors(cd, connectors);

                    foreach (Connector connector in connectors)
                    {
                        foreach (Connection con in connector.Connections)
                        {
                            SelectionService.RemoveFromSelection(con);
                            this.Children.Remove(con);
                        }
                    }
                    SelectionService.RemoveFromSelection(ToRemove);
                    this.Focus();
                    this.Children.Remove(ToRemove);
                }
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        protected override void OnDrop(DragEventArgs e)
        {
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

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

                    if (content != null)
                    {
                        itemCounter = this.Children.OfType <DesignerItem>().Where(x => x.Tag.ToString() == dragObject.Class).Count();

                        newItem         = new DesignerItem(Guid.NewGuid(), dragObject.Class, ++itemCounter);
                        newItem.Content = 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);

                        DrawConnection(newItem.ID, OperationGuid);
                        ResourceWindow.UpdateResource(newItem);

                        //update selection
                        this.SelectionService.SelectItem(newItem);
                        newItem.Focus();
                    }
                    e.Handled = true;
                }
                else
                {
                    newItem = dragObject.DesignerItem;
                    if (!(newItem.Parent is DesignerCanvas))
                    {
                        newItem.Width  = 60;
                        newItem.Height = 60;

                        //Toolbox.Items.Remove(Toolbox.Items.OfType<ToolboxItem>().Where(x => x.DesignerItem == newItem).FirstOrDefault());
                        ((ToolboxItem)Toolbox.Items[0]).Content = null;
                        Toolbox.Items.RemoveAt(0);
                        //var parent = newItem.Parent;


                        Point position = e.GetPosition(this);
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));

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

                        SetConnectorDecoratorTemplate(newItem);

                        DrawConnection(newItem.ID, OperationGuid);
                        ResourceWindow.UpdateResource(newItem);

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

                    e.Handled = true;
                }
                newItem.MouseDoubleClick += DesignerItem_MouseDoubleClick;

                //MessageBox.Show("resourcecanvas: " + newItem.BoundLogicItem.ID.ToString());
            }
        }
Ejemplo n.º 10
0
        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 = new DesignerItem();
                    newItem.Content = 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();

                    if (content.GetType() == typeof(ImageLayout))
                    {
                        ((ImageLayout)content).ShowTitle();
                    }
                }

                e.Handled = true;
            }
        }