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); }
public void AddItem(Object content, Point?desiredPosition = null, Size?desiredSize = null) { if (content != null) { DesignerItem newItem = new DesignerItem(); newItem.Content = content; Point position = desiredPosition.HasValue ? desiredPosition.Value : new Point(); if (desiredSize.HasValue) { newItem.Width = desiredSize.Value.Width; newItem.Height = desiredSize.Value.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); listDesignerItem.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection //this.SelectionService.SelectItem(newItem); //newItem.Focus(); } }
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; } }
public DesignerItem AddDesignerItem(FrameworkElement item, Point position, Size?size, int layer = 0, bool insertInBackground = false, Guid?itemGuid = null) { DesignerItem newItem = new DesignerItem(); if (itemGuid != null) { newItem.ID = itemGuid.Value; } 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; if (insertInBackground) { newItem.ZIndex = 0; this.Children.Insert(0, newItem); } else { this.Children.Add(newItem); } SetConnectorDecoratorTemplate(newItem); //update selection //this.SelectionService.SelectItem(newItem); //newItem.Focus(); raiseDesignerItemAdded(item, newItem); bool layerVisible = false; if (!visibleLayers.TryGetValue(layer, out layerVisible) || layerVisible) { item.Visibility = System.Windows.Visibility.Visible; } else { item.Visibility = System.Windows.Visibility.Hidden; } //updateVisibleDesigneritems(); return(newItem); }
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; } }
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"); } }
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; } }
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)); } this.Children.Add(newItem); //update selection foreach (ISelectable item in this.SelectedItems) { item.IsSelected = false; } SelectedItems.Clear(); newItem.IsSelected = true; this.SelectedItems.Add(newItem); } e.Handled = true; } }
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; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { newItem = new DesignerItem(); newItem.Style = this.TryFindResource("DesignerItemStyle") as Style; newItem.Content = content; Point position = e.GetPosition(this); //if (content.MinHeight != 0 && content.MinWidth != 0) //{ // newItem.Width = content.MinWidth * 2; ; // newItem.Height = content.MinHeight * 2; //} //else //{ // newItem.Width = 65; // newItem.Height = 65; //} double unitwidth = this.ActualWidth / MyCols; double unitheight = this.ActualHeight / MyRows; newItem.Width = unitwidth; newItem.Height = unitheight; double left = Math.Floor(position.X / unitwidth) * unitwidth; double top = Math.Floor(position.Y / unitheight) * unitheight; DesignerCanvas.SetLeft(newItem, Math.Max(0, left /*position.X - newItem.Width / 2*/)); DesignerCanvas.SetTop(newItem, Math.Max(0, top /*position.Y - newItem.Height / 2*/)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }
protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { base.OnMouseDoubleClick(e); DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; if (designer != null) { double h = designer.ActualHeight / designer.MyRows; double w = designer.ActualWidth / designer.MyCols; double left = DesignerCanvas.GetLeft(this); double top = DesignerCanvas.GetTop(this); double newleft = System.Math.Floor(left / w) * w; double newtop = System.Math.Floor(top / h) * h; double newright = System.Math.Ceiling((left + this.ActualWidth) / w) * w; double newbottom = System.Math.Ceiling((top + this.ActualHeight) / h) * h; DesignerCanvas.SetLeft(this, newleft); DesignerCanvas.SetTop(this, newtop); this.Width = newright - newleft; this.Height = newbottom - newtop; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; FrameworkElement content = XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) as FrameworkElement; if (content != null) { newItem = new DesignerItem(); newItem.Content = content; Point position = e.GetPosition(this); if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2;; newItem.Height = content.MinHeight * 2; } else { newItem.Width = 65; newItem.Height = 65; } DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); this.Children.Add(newItem); this.DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }
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); }
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()); } }