/// <summary> /// Destroy the current rubberband viewmodel to make way /// for a new rubber band selection based on a new viewmodel and view. /// </summary> public void ResetRubberBand() { if (_RubberBand != null) { _RubberBand = null; } }
/// <summary> /// Is called if the user begins a drag operation on the canvas and there is no other /// mouse handler (eg, AssociationMouseHandler) currently activated. /// /// Otherwise, the OnShapeDragBegin method of the other mouse handler is executed and /// this method is completely ignorred for the current drag operation. /// </summary> /// <param name="position"></param> /// <param name="shape"></param> void ICanvasViewMouseHandler.OnShapeDragBegin(Point position, ShapeViewModelBase shape) { if (shape != null) { // Activate shape selection if user starts to drag a shape if (shape.IsSelected == false) { ((ICanvasViewMouseHandler)this).OnShapeClick(this.mDragShape); } } else // user starts a drag operation on the canvas so we setup a rubber band adorner command { // to implement multi object selection via rubber band if (this.mCurrentMouseHandler == this) { // Clear current selection if no control key is pressed on the keyboard (which would allow adding selected items) if ((Keyboard.IsKeyDown(Key.LeftCtrl) == false && Keyboard.IsKeyDown(Key.RightCtrl) == false)) { CanvasViewModel.SelectedItem.SelectShape(null); } RubberBandViewModel vm = this.GetRubberBand(position); // Create a new mouse handler command, attach event on completion, and hook it into the system CreateRubberBandMouseHandler handler = new CreateRubberBandMouseHandler(vm, this.CanvasViewModel); handler.RubberBandSelection += handler_RubberBandSelection; // Hook up into frame work system this.CanvasViewModel.BeginCanvasViewMouseHandler(handler); this.BeginMouseOperation(); //this.mCurrentMouseHandler = this.CanvasViewModel.CanvasViewMouseHandler; } } }
/// <summary> /// Destroy the current rubberband viewmodel to make way /// for a new rubber band selection based on a new viewmodel and view. /// </summary> public void ResetRubberBand() { if (this.mRubberBand != null) { this.mRubberBand = null; } }
/// <summary> /// Create a new rubber band adorner along with its viewmodel in this canvas viewmodel. /// </summary> /// <param name="position"></param> /// <returns></returns> private RubberBandViewModel GetRubberBand(Point position) { this.DestroyRubberband(); RubberBandViewModel rbViewModel = this.CanvasViewModel.RubberBand; rbViewModel.IsVisible = false; rbViewModel.Position = new Point(position.X, position.Y); rbViewModel.EndPosition = new Point(position.X, position.Y); if (this.mRubberbandAdorner == null) { this.mRubberbandAdorner = new RubberbandAdorner(this, new Point(position.X, position.Y)); this.mRubberbandAdorner.Visibility = System.Windows.Visibility.Hidden; this.mRubberbandAdorner.Width = this.mRubberbandAdorner.Height = 0; // EndPosition binding with converter { var endPosBinding = new Binding("EndPosition"); endPosBinding.Source = rbViewModel; BindingOperations.SetBinding(this.mRubberbandAdorner, RubberbandAdorner.EndPointProperty, endPosBinding); } // Visibility binding with converter { var visiblityBinding = new Binding("IsVisible"); visiblityBinding.Source = rbViewModel; visiblityBinding.Converter = CanvasView.mBoolToVisConverter; BindingOperations.SetBinding(this.mRubberbandAdorner, RubberbandAdorner.VisibilityProperty, visiblityBinding); } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Add(this.mRubberbandAdorner); } } rbViewModel.IsVisible = true; return(rbViewModel); }