How to scale rectangle RRS feed

  • Question

  • Hello,

    I have a Rectangle inside a Canvas.  I would like the user to be able drag and scale the rectangle using Manipulation.  I can successfully drag, but I cannot scale.  In the ManipulationDelta, the only example I have seen for scaling is this:

    _compositeTransform->ScaleX *= e->Delta.Scale;
    _compositeTransform->ScaleY *= e->Delta.Scale;

    But e->Delta.Scale is always 1.0 so it has no effect.  (I don't have a touch screen and so only using a mouse.  Is there a way to do this with a mouse?

    I have also tried the following:

    _compositeTransform->ScaleX += (+ or -)0.001;
    _compositeTransform->ScaleY += (+ or -)0.001;

    But the rectangle always grows and doesn't shrink when the value is negative.

    What is the best way of doing this?


    Saturday, February 16, 2013 2:33 AM

All replies

  • Hi SAP,

    Your first code snippet looks correct. You don't give enough context to explain why your second snippet would grow when the value was negative, but the additive scaling will work oddly and probably not act as your customers expect.

    You can test scaling with the mouse in the simulator. See "Pinch and Zoom" section on Running Windows Store apps in the simulator

    Since pinch and zoom scaling requires two points it needs to be done by touch. Mouse manipulations will always leave the scaling factor at 1.0.


    Saturday, February 16, 2013 3:33 AM
  • Ok, I think I'll just have to resort to standard mouse operations (enter/leave/pressed/released/move).

    In that case, what is the proper way to move/resize a rectangle inside a canvas?  The first thing that I would try is this code (as a replacement for SetWindowPos):

    Canvas::SetLeft ( _rect, x );
    Canvas::SetTop ( _rect, y );
    _rect->Width = newWidth;
    _rect->Height = newHeight;

    Is this assumption correct?  Or is there a better way?



    • Proposed as answer by Jesse Jiang Tuesday, February 19, 2013 1:53 AM
    • Unproposed as answer by Jesse Jiang Tuesday, February 19, 2013 1:58 AM
    Saturday, February 16, 2013 7:02 PM