private GraphicInstance CreateGraphicVisualizedInstance(Type type, LogicalInstance logicalInstance, DragEventArgs args) { Point position = args.GetPosition(this); double width = (double)type.GetProperty("Width").GetValue(Activator.CreateInstance(type), null); double height = (double)type.GetProperty("Height").GetValue(Activator.CreateInstance(type), null); GraphicInstance graphicInstance = null; if (type.IsSubclassOf(typeof(NodeType))) { ParentableInstance parent = (this.Content as CanvasItemsControl).FindParent(position, graphicInstance); graphicInstance = new NodeInstance { X = position.X, Y = position.Y, Width = (width != 0 && !double.IsNaN(width)) ? width : 200, Height = (height != 0 && !double.IsNaN(height)) ? height : 200, LogicalInstance = logicalInstance, Parent = parent }; } else { graphicInstance = new EdgeInstance { X = position.X, Y = position.Y, Width = (width != 0 && !double.IsNaN(width)) ? width : 200, Height = (height != 0 && !double.IsNaN(height)) ? height : 200, LogicalInstance = logicalInstance, Parent = InstancesManager.Instance.CanvasRootElement }; } return(graphicInstance); }
private void treeViewDDTarget_DragOver(object sender, Microsoft.Windows.DragEventArgs e) { var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(treeView), treeView).Where(element => element is TreeViewItem).Cast <TreeViewItem>(); if (elements.Any()) { UIManager.Instance.SelectedGraphicInstance = elements.First().DataContext as GraphicInstance; } }