Defines the data-model for a simple displayable rectangle.
Inheritance: INotifyPropertyChanged
Example #1
0
        /// <summary>
        /// Event raised when the mouse cursor is moved when over a Rectangle.
        /// </summary>
        private void Rectangle_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseHandlingMode != MouseHandlingMode.DraggingRectangles)
            {
                //
                // We are not in rectangle dragging mode, so don't do anything.
                //
                return;
            }

            Point  curContentPoint     = e.GetPosition(content);
            Vector rectangleDragVector = curContentPoint - origContentMouseDownPoint;

            //
            // When in 'dragging rectangles' mode update the position of the rectangle as the user drags it.
            //

            origContentMouseDownPoint = curContentPoint;

            Rectangle     rectangle   = (Rectangle)sender;
            RectangleData myRectangle = (RectangleData)rectangle.DataContext;

            myRectangle.X += rectangleDragVector.X;
            myRectangle.Y += rectangleDragVector.Y;

            ExpandContent();

            e.Handled = true;
        }
Example #2
0
        /// <summary>
        /// Event raised when a mouse button is clicked down over a Rectangle.
        /// </summary>
        private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e)
        {
            content.Focus();
            Keyboard.Focus(content);

            Rectangle     rectangle   = (Rectangle)sender;
            RectangleData myRectangle = (RectangleData)rectangle.DataContext;

            myRectangle.IsSelected = true;

            if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
            {
                //
                // When the shift key is held down special zooming logic is executed in content_MouseDown,
                // so don't handle mouse input here.
                //
                return;
            }

            if (mouseHandlingMode != MouseHandlingMode.None)
            {
                //
                // We are in some other mouse handling mode, don't do anything.
                return;
            }

            mouseHandlingMode         = MouseHandlingMode.DraggingRectangles;
            origContentMouseDownPoint = e.GetPosition(content);

            rectangle.CaptureMouse();

            e.Handled = true;
        }