protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); var 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))); var content = ""; if (content != null) { var vm = DataContext as EditorWindowViewModel; if (vm == null) { throw new ArgumentException("DataContext as ConstructorViewModel"); return; } var visualProperties = new VisualProperties(); //visualProperties.Size = var elementProperties = new ElementProperties(visualProperties, new DomainProperties()); var initialElement = dragObject.InitialElementViewModel.InitialElement; var model = new Element(initialElement, elementProperties); var elementViewModel = new ElementViewModel(model); elementViewModel.ElementPropertiesViewModel.Name = string.Format("{0} {1}", initialElement.Name, count++); newItem = new DesignerItem(elementViewModel); newItem.SizeChanged += (sender, args) => { var newSize = args.NewSize; elementViewModel.ElementPropertiesViewModel.ElementVisualPropertiesViewModel.Size = new ElementSize(newSize.Height, newSize.Width); }; var button = new Ellipse { //Width = 100, //Height = 100, Fill = Brushes.Aqua }; newItem.Content = ResourceUtil.GetResourceByName(dragObject.InitialElementViewModel.StyleName) ?? button; var position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { var desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; SetLeft(newItem, Math.Max(0, position.X - newItem.Width/2)); SetTop(newItem, Math.Max(0, position.Y - newItem.Height/2)); } else { SetLeft(newItem, Math.Max(0, position.X)); SetTop(newItem, Math.Max(0, position.Y)); } newItem.SetCoords(); SetZIndex(newItem, Children.Count); Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection SelectionService.SelectItem(newItem); newItem.Focus(); vm.Add(newItem.ElementViewModel); } e.Handled = true; } }
private static DesignerItem DeserializeDesignerItem(XElement itemXML, Guid id, double OffsetX, double OffsetY) { var 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.ParentID = new Guid(itemXML.Element("ParentID").Value); item.IsGroup = bool.Parse(itemXML.Element("IsGroup").Value); SetLeft(item, double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + OffsetX); SetTop(item, double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + OffsetY); SetZIndex(item, int.Parse(itemXML.Element("zIndex").Value)); var content = XamlReader.Load(XmlReader.Create(new StringReader(itemXML.Element("Content").Value))); item.Content = content; return item; }
private void SetConnectorDecoratorTemplate(DesignerItem item) { if (item.ApplyTemplate() && item.Content is UIElement) { var template = DesignerItem.GetConnectorDecoratorTemplate(item.Content as UIElement); var 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 SelectionService.CurrentSelection.OfType<DesignerItem>() where item.ParentID == Guid.Empty select item; var rect = GetBoundingRectangle(items); var groupItem = new DesignerItem(); groupItem.IsGroup = true; groupItem.Width = rect.Width; groupItem.Height = rect.Height; SetLeft(groupItem, rect.Left); SetTop(groupItem, rect.Top); var groupCanvas = new Canvas(); groupItem.Content = groupCanvas; SetZIndex(groupItem, Children.Count); Children.Add(groupItem); foreach (var item in items) item.ParentID = groupItem.ID; SelectionService.SelectItem(groupItem); }