Beispiel #1
0
        private void DragBottom(double scale, DesignItem item, SelectionService selectionService)
        {
            IEnumerable<DesignItem> groupItems = selectionService.GetGroupMembers(item).Cast<DesignItem>();
            double groupTop = Canvas.GetTop(item);
            foreach (DesignItem groupItem in groupItems)
            {
                double groupItemTop = Canvas.GetTop(groupItem);
                double delta = (groupItemTop - groupTop) * (scale - 1);

                Canvas.SetTop(groupItem, groupItemTop + delta);
                groupItem.Height = groupItem.ActualHeight * scale;
            }
        }
Beispiel #2
0
        private void DragLeft(double scale, DesignItem item, SelectionService selectionService)
        {
            IEnumerable<DesignItem> groupItems = selectionService.GetGroupMembers(item).Cast<DesignItem>();

            double groupLeft = Canvas.GetLeft(item) + item.Width;
            foreach (DesignItem groupItem in groupItems)
            {
                double groupItemLeft = Canvas.GetLeft(groupItem);
                double delta = (groupLeft - groupItemLeft) * (scale - 1);
                Canvas.SetLeft(groupItem, groupItemLeft - delta);
                groupItem.Width = groupItem.ActualWidth * scale;
            }
        }
 private static DesignItem DeserializeDesignItem(XElement itemXML, Guid id, double OffsetX, double OffsetY)
 {
     DesignItem item = new DesignItem(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.Content = content;
     return item;
 }
        public static DesignItem CreateDesignItem(DesignItemInfo designItemInfo)
        {
            var currentDate = DateTime.Now;
            designItemInfo.CreateDate = currentDate;
            designItemInfo.ModifyDate = currentDate;
            var shape = new Shape();
            var shapeInfoUnit = new ItemShapeInfoUnit(designItemInfo);
            shape.ShapeInfoUnit = shapeInfoUnit;
            shape.IsHitTestVisible = false;
            shape.Style = Application.Current.Resources[designItemInfo.StyleKey] as Style;
            if (designItemInfo.SvgBuffer != null)
            {
                using (var stream = new MemoryStream(designItemInfo.SvgBuffer))
                {
                    var svgDrawing = SvgHelper.CreateSvgImage(stream); //SvgHelper.CreateSvgViewBox(stream);
                    if (svgDrawing != null)
                    {
                        shapeInfoUnit.SvgDrawing = svgDrawing;
                        shape.SetBinding(Shape.ContentProperty, BindingHelper.CreateBinding(shapeInfoUnit, "SvgDrawing"));
                    }
                }
            }
            shape.SetBinding(Shape.TextProperty, BindingHelper.CreateBinding(designItemInfo, "Text"));
            if (!string.IsNullOrEmpty(designItemInfo.DesignInfo.Backgroud))
            {
                var brushConverter = new BrushConverter();
                shape.Background = (Brush)brushConverter.ConvertFromString(designItemInfo.DesignInfo.Backgroud);
            }
            var designItem = new DesignItem(designItemInfo.ID);
            designItem.ParentID = designItemInfo.ParentID;
            designItem.Content = shape;
            designItem.SetBinding(DesignItem.LinkButtonVisibilityProperty, BindingHelper.CreateBinding(designItemInfo, "LinkButtonVisibility"));
            designItem.SetBinding(DesignItem.WidthProperty, BindingHelper.CreateBinding(designItemInfo,"Width"));
            designItem.SetBinding(DesignItem.HeightProperty, BindingHelper.CreateBinding(designItemInfo, "Height"));
            designItem.SetBinding(DesignCanvas.LeftProperty, BindingHelper.CreateBinding(designItemInfo, "X"));
            designItem.SetBinding(DesignCanvas.TopProperty, BindingHelper.CreateBinding(designItemInfo, "Y"));
            designItem.SetBinding(DesignCanvas.ZIndexProperty, BindingHelper.CreateBinding(designItemInfo, "ZIndex"));

            return designItem;
        }
        void thumbDragThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            this.HitDesignItem = null;
            this.HitConnector = null;
            this.pathGeometry = null;
            this.Cursor = Cursors.Cross;
            this.connection.StrokeDashArray = new DoubleCollection(new double[] { 1, 2 });

            if (sender == sourceDragThumb)
            {
                fixConnector = connection.Sink;
                dragConnector = connection.Source;
            }
            else if (sender == sinkDragThumb)
            {
                dragConnector = connection.Sink;
                fixConnector = connection.Source;
            }
        }
        void thumbDragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (HitConnector != null)
            {
                if (connection != null)
                {
                    if (connection.Source == fixConnector)
                        connection.Sink = this.HitConnector;
                    else
                        connection.Source = this.HitConnector;
                }
            }

            this.HitDesignItem = null;
            this.HitConnector = null;
            this.pathGeometry = null;
            this.connection.StrokeDashArray = null;
            this.InvalidateVisual();
        }
        private void HitTesting(Point hitPoint)
        {
            bool hitConnectorFlag = false;

            DependencyObject hitObject = designCanvas.InputHitTest(hitPoint) as DependencyObject;
            while (hitObject != null && fixConnector!=null &&
                   hitObject != fixConnector.ParentDesignItem &&
                   hitObject.GetType() != typeof(DesignCanvas))
            {
                if (hitObject is Connector)
                {
                    HitConnector = hitObject as Connector;
                    hitConnectorFlag = true;
                }

                if (hitObject is DesignItem)
                {
                    HitDesignItem = hitObject as DesignItem;
                    if (!hitConnectorFlag)
                        HitConnector = null;
                    return;
                }
                hitObject = VisualTreeHelper.GetParent(hitObject);
            }

            HitConnector = null;
            HitDesignItem = null;
        }
 private void SetConnectorDecoratorTemplate(DesignItem item)
 {
     if (item.ApplyTemplate() && item.Content is UIElement)
     {
         ControlTemplate template = DesignItem.GetConnectorDecoratorTemplate(item.Content as UIElement);
         Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control;
         if (decorator != null && template != null)
             decorator.Template = template;
     }
 }
        private void Group_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var items = from item in this.SelectionService.CurrentSelection.OfType<DesignItem>()
                        where item.ParentID == Guid.Empty
                        select item;

            Rect rect = GetBoundingRectangle(items);

            DesignItem groupItem = new DesignItem();
            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 (DesignItem item in items)
                item.ParentID = groupItem.ID;

            this.SelectionService.SelectItem(groupItem);
            this.CurrentDesignItemInfos.Add(new DesignItemInfo() { ID = groupItem.ID, ParentID = groupItem.ParentID, IsGroup = true, X = (decimal)rect.Left, Y = (decimal)rect.Top, Width = (decimal)rect.Width, Height = (decimal)rect.Height });
        }