void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e) { DesignerItem designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem; if (designerItem != null) { EntityDiagramControl entityControl = VisualItemHelper.FindChild <EntityDiagramControl>(designerItem); if (entityControl != null) { entityControl.UpdateConnections(); } } }
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseDown(e); if (DataContext is IWorkspaceViewModel) { (DataContext as IWorkspaceViewModel).SetSelected(); DesignerItem control = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem; if (control != null) { control.Focus(); } } }
void DesignerItem_Loaded(object sender, RoutedEventArgs e) { // if DragThumbTemplate and ConnectorDecoratorTemplate properties of this class // are set these templates are applied; // Note: this method is only executed when the Loaded event is fired, so // setting DragThumbTemplate or ConnectorDecoratorTemplate properties after // will have no effect. if (base.Template != null) { ContentPresenter contentPresenter = this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter; if (contentPresenter != null) { UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement; if (contentVisual != null) { DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb; Control connectorDecorator = this.Template.FindName("PART_ConnectorDecorator", this) as Control; if (thumb != null) { ControlTemplate template = DesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate; if (template != null) { thumb.Template = template; } } if (connectorDecorator != null) { ControlTemplate template = DesignerItem.GetConnectorDecoratorTemplate(contentVisual) as ControlTemplate; if (template != null) { connectorDecorator.Template = template; } } } } } }
private static void CalculateDragLimits(DesignerCanvas designer, IEnumerable <IDiagramWorkspaceViewModel> selectedDesignerItems, out double minLeft, out double minTop, out double minDeltaHorizontal, out double minDeltaVertical) { minLeft = double.MaxValue; minTop = double.MaxValue; minDeltaHorizontal = double.MaxValue; minDeltaVertical = double.MaxValue; // drag limits are set by these parameters: canvas top, canvas left, minHeight, minWidth // calculate min value for each parameter for each item foreach (IDiagramWorkspaceViewModel item in selectedDesignerItems) { DesignerItem itemControl = VisualItemHelper.FindChild <DesignerItem>(designer, item) as DesignerItem; if (itemControl != null) { minLeft = double.IsNaN(item.X) ? 0 : Math.Min(item.X, minLeft); minTop = double.IsNaN(item.Y) ? 0 : Math.Min(item.Y, minTop); minDeltaVertical = Math.Min(minDeltaVertical, itemControl.ActualHeight - itemControl.MinHeight); minDeltaHorizontal = Math.Min(minDeltaHorizontal, itemControl.ActualWidth - itemControl.MinWidth); } } }
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem; DesignerCanvas designer = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(designerItem) as DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { IDiagramWorkspaceViewModel designerView = designer.DataContext as IDiagramWorkspaceViewModel; if (designerView != null) { double minLeft = double.MaxValue; double minTop = double.MaxValue; foreach (IDiagramWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>()) { minLeft = double.IsNaN(item.X) ? 0 : Math.Min(item.X, minLeft); minTop = double.IsNaN(item.Y) ? 0 : Math.Min(item.Y, minTop); } double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange); double deltaVertical = Math.Max(-minTop, e.VerticalChange); // move diagram entities (TODO: handle arcs later or a separate view model interface for arcs) foreach (IDiagramEntityWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>()) { item.X += deltaHorizontal; item.Y += deltaVertical; if (item.ZIndex < designerView.ZIndex) { item.ZIndex = ++designerView.ZIndex; } } designer.InvalidateMeasure(); e.Handled = true; } } }
void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = VisualItemHelper.VisualUpwardSearch <DesignerItem>(this) as DesignerItem; DesignerCanvas designer = VisualItemHelper.VisualUpwardSearch <DesignerCanvas>(designerItem) as DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { IDiagramWorkspaceViewModel designerView = designer.DataContext as IDiagramWorkspaceViewModel; if (designerView != null) { double minLeft, minTop, minDeltaHorizontal, minDeltaVertical; double dragDeltaVertical, dragDeltaHorizontal; CalculateDragLimits(designer, designerView.SelectedItems.OfType <DiagramEntityViewModel>(), out minLeft, out minTop, out minDeltaHorizontal, out minDeltaVertical); // resize diagram entities (TODO: handle arcs later or a separate view model interface for arcs) foreach (IDiagramEntityWorkspaceViewModel item in designerView.SelectedItems.OfType <IDiagramEntityWorkspaceViewModel>()) { DesignerItem itemControl = VisualItemHelper.FindChild <DesignerItem>(designer, item) as DesignerItem; if (itemControl != null) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical); item.Height = Math.Max(MinHeight, itemControl.ActualHeight - dragDeltaVertical); break; case VerticalAlignment.Top: dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); item.Y += dragDeltaVertical; item.Height = Math.Max(MinHeight, itemControl.ActualHeight - dragDeltaVertical); break; default: break; } switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); item.X += dragDeltaHorizontal; item.Width = Math.Max(MinWidth, itemControl.ActualWidth - dragDeltaHorizontal); break; case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal); item.Width = Math.Max(MinWidth, itemControl.ActualWidth - dragDeltaHorizontal); break; default: break; } } } e.Handled = true; } } }