Пример #1
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;
                Image        content = (Image)XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    newItem         = new DesignerItem();
                    newItem.Content = content;

                    Assembly  a   = Assembly.GetAssembly(typeof(IActivity));
                    Type      t   = a.GetType("IntegraDesigner." + content.Tag);
                    IActivity act = (IActivity)Activator.CreateInstance(t);
                    act.AppName      = content.Tag.ToString();
                    newItem.Activity = act;
                    ToolTipService.SetToolTip(newItem, act.AppName + ": " + act.Description);


                    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;
            }
        }
Пример #2
0
        private void SetConnectorDecoratorTemplate(DesignerItem item)
        {
            if (item.ApplyTemplate() && item.Content is UIElement)
            {
                ControlTemplate template  = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement);
                Control         decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control;
                if (decorator != null && template != null)
                {
                    decorator.Template = template;
                }

                if (item.GetType().ToString() == "Connection")
                {
                    Shape s = item.Template.FindName("PART_ConnectionPath", item) as Shape;
                    s.Stroke = Brushes.Tomato;
                }
            }
        }
        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;
                Image content = (Image)XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    newItem = new DesignerItem();
                    newItem.Content = content;

                     Assembly a = Assembly.GetAssembly(typeof(IActivity));
                     Type t = a.GetType("IntegraDesigner." + content.Tag );
                     IActivity act = (IActivity)Activator.CreateInstance(t);
                     act.AppName = content.Tag.ToString();
                     newItem.Activity = act;
                     ToolTipService.SetToolTip(newItem,act.AppName + ": " +act.Description);
                    

                    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;
            }
        }
        private void SetConnectorDecoratorTemplate(DesignerItem item)
        {
            if (item.ApplyTemplate() && item.Content is UIElement)
            {
                ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement);
                Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control;
                if (decorator != null && template != null)
                    decorator.Template = template;

                if (item.GetType().ToString() == "Connection")
                {
                    Shape s = item.Template.FindName("PART_ConnectionPath", item) as Shape;
                    s.Stroke = Brushes.Tomato;
                }
            }
        }
        private void Group_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var items = from item in this.SelectionService.CurrentSelection.OfType<DesignerItem>()
                        where item.ParentID == Guid.Empty
                        select item;

            Rect rect = GetBoundingRectangle(items);

            DesignerItem groupItem = new DesignerItem();
            groupItem.IsGroup = true;
            groupItem.Width = rect.Width;
            groupItem.Height = rect.Height;
            Canvas.SetLeft(groupItem, rect.Left);
            Canvas.SetTop(groupItem, rect.Top);
            Canvas groupCanvas = new Canvas();
            groupItem.Content = groupCanvas;
            Canvas.SetZIndex(groupItem, this.Children.Count);
            this.Children.Add(groupItem);

            foreach (DesignerItem item in items)
                item.ParentID = groupItem.ID;

            this.SelectionService.SelectItem(groupItem);
        }
        private static DesignerItem DeserializeDesignerItem(XElement itemXML, Guid id, double OffsetX, double OffsetY)
        {
            DesignerItem item = new DesignerItem(id);
           // item.Width = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture);
            //item.Height = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture);
            item.Width = 70;
            item.Height = 43;
            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.Content = content;
            String App = itemXML.Element("App").Value.ToString();
            Assembly a = Assembly.GetAssembly(typeof(IActivity));
            Type t = a.GetType("IntegraDesigner." + App);
            item.Activity = (IActivity)Activator.CreateInstance(t);
            ToolTipService.SetToolTip(item, App);


            //Para cualquier actividad deserializo
            XElement test = itemXML.Element("Activity");
            
            //saco el header que no necesito
            string aux =test.ToString();
            aux = aux.Replace("<Activity>", "");
            aux = aux.Replace("</Activity>", "");

            item.Activity = (IActivity) DeSerializeAsXElement(aux, item.Activity);
          
            return item;
        }