Beispiel #1
0
        void VisualCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Released || NewCanvasItem == null)
            {
                return;
            }
            if (IsDragStart)
            {
                CurrentMousePoint = e.GetPosition(sender as IInputElement);
                Debug.WriteLine(CurrentMousePoint);
                var x = Math.Min(CurrentMousePoint.X, StartMousePoint.X);
                var y = Math.Min(CurrentMousePoint.Y, StartMousePoint.Y);

                var width  = Math.Max(CurrentMousePoint.X, StartMousePoint.X) - x;
                var height = Math.Max(CurrentMousePoint.Y, StartMousePoint.Y) - y;


                NewCanvasItem.SetCurrentValue(FrameworkElement.WidthProperty, width);
                NewCanvasItem.SetCurrentValue(FrameworkElement.HeightProperty, height);

                Canvas.SetLeft(NewCanvasItem, x);
                Canvas.SetTop(NewCanvasItem, y);

                IEditableCollectionViewAddNewItem items = this.Items;
                items.CommitEdit();
            }
        }
Beispiel #2
0
 void VisualCanvas_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (IsDragStart)
     {
         IsDragStart = false;
         if (MinItemWidth != Double.NaN && (Double)NewCanvasItem.GetValue(FrameworkElement.WidthProperty) < MinItemWidth)
         {
             NewCanvasItem.SetCurrentValue(FrameworkElement.WidthProperty, MinItemWidth);
         }
         if (MinItemHeight != Double.NaN && (Double)NewCanvasItem.GetValue(FrameworkElement.HeightProperty) < MinItemHeight)
         {
             NewCanvasItem.SetCurrentValue(FrameworkElement.HeightProperty, MinItemHeight);
         }
         IEditableCollectionViewAddNewItem items = this.Items;
         items.CommitEdit();
         NewItem       = null;
         NewCanvasItem = null;
         e.Handled     = true;
         Mouse.Capture(this, CaptureMode.None);
     }
 }