ManipulationDelta.Scale Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the amount the manipulation has resized as a multiplier.

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public Vector Scale { get; private set; }

Property Value

Type: System.Windows.Vector

The amount the manipulation has resized.

The Scale and Expansion properties both report a resizing manipulation. The difference between the two is the way in which the value is reported. The Scale property reports the value as a multiplier. If Scale is 0.5, the manipulation is interpreted as decreasing the size by 50 percent. If Scale is 2, the manipulation is interpreted as increasing the size by 100 percent. The Expansion property reports the resizing manipulation in device-independent units (1/96th inch per unit).

The following example shows an event handler for the ManipulationDelta event. The example applies the Translation, Scale, and Rotation properties to move, resize, and rotate a Rectangle. This example is part of a larger example in Walkthrough: Creating Your First Touch Application.

void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{

    // Get the Rectangle and its RenderTransform matrix.
    Rectangle rectToMove = e.OriginalSource as Rectangle;
    Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

    // Rotate the Rectangle.
    rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, 
                         e.ManipulationOrigin.X, 
                         e.ManipulationOrigin.Y);

    // Resize the Rectangle.  Keep it square 
    // so use only the X value of Scale.
    rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, 
                        e.DeltaManipulation.Scale.X, 
                        e.ManipulationOrigin.X,
                        e.ManipulationOrigin.Y);

    // Move the Rectangle.
    rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                          e.DeltaManipulation.Translation.Y);

    // Apply the changes to the Rectangle.
    rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

    Rect containingRect =
        new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

    Rect shapeBounds =
        rectToMove.RenderTransform.TransformBounds(
            new Rect(rectToMove.RenderSize));

    // Check if the rectangle is completely in the window.
    // If it is not and intertia is occuring, stop the manipulation.
    if (e.IsInertial && !containingRect.Contains(shapeBounds))
    {
        e.Complete();
    }


    e.Handled = true;
}

.NET Framework
Available since 4.0
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: