Freigeben über


MultiScaleImage.ZoomAboutLogicalPoint Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Enables a user to zoom in on a point of the MultiScaleImage.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub ZoomAboutLogicalPoint ( _
    zoomIncrementFactor As Double, _
    zoomCenterLogicalX As Double, _
    zoomCenterLogicalY As Double _
)
public void ZoomAboutLogicalPoint(
    double zoomIncrementFactor,
    double zoomCenterLogicalX,
    double zoomCenterLogicalY
)

Parameters

  • zoomIncrementFactor
    Type: System.Double
    Specifies the zoom. This number is greater than 0. A value of 1 specifies that the image fit the allotted page size exactly. A number greater than 1 specifies to zoom in. If a value of 0 or less is used, failure is returned and no zoom changes are applied.
  • zoomCenterLogicalX
    Type: System.Double
    X coordinate for the point on the MultiScaleImage that is zoomed in on. This is a logical point (between 0 and 1).
  • zoomCenterLogicalY
    Type: System.Double
    Y coordinate for the point on the MultiScaleImage that is zoomed in on. This is a logical point (between 0 and 1).

Remarks

This method enables zooming and panning on the MultiScaleImage. The first parameter (zoomIncrementFactor) is the zoom multiplier which is incremented from the current zoom factor of the image. For example, a value of 1 specifies the default zoom and a value of 3 specifies that it is zoomed in 3 times. If you want to zoom again using the same value, you would zoom in at 3 * 3 which is 9 times from the default size.

The second and third parameters of the ZoomAboutLogicalPoint method are the respective x and y coordinates of the logical point of where to zoom around (and where to pan to). A logical point uses normalized values (between 0 and 1) for x and y positions within the image. Therefore, the value 0.5, 0.5 is in the middle of the image because 0.5 is in the middle of 0 and 1. If you specified a coordinate value less than or equal to 0 or greater than or equal to 1, the image would pan completely out of view.

Examples

The following example shows how to use the ZoomAboutLogicalPoint method to zoom in on the center of an image when the mouse pointer moves over the image, and then return back when the mouse pointer leaves the image.

Run this sample

<Grid x:Name="LayoutRoot" Background="White">
    <MultiScaleImage x:Name="MyMSI" Source="source/dzc_output.xml"  MouseEnter="MyMSI_MouseEnter" MouseLeftButtonDown="MyMSI_LeftButtonDown" 
                     ImageOpenSucceeded="MyMSI_ImageOpenSucceeded" MouseLeave="MyMSI_MouseLeave" />

</Grid>
Private Sub MyMSI_ImageOpenSucceeded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Turn the animations off when the image first loads. This avoids
    ' the default behavior of the image initially zooming into view. 
    ' However, you will probably want to turn the animations on later
    ' so that the user will have animations when they pan and zoom.
    MyMSI.UseSprings = False

End Sub

Private Sub MyMSI_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
    If MyMSI.UseSprings = False Then
        MyMSI.UseSprings = True
    End If

    ' The ZoomAboutLogicalPoint method allows you to zoom and pan
    ' in the same step. The first parameter is the zoom (3x) and the
    ' second and third parameters are the respective x and y coordinates
    ' of the logical point to zoom around.
    Me.MyMSI.ZoomAboutLogicalPoint(3, 0.5, 0.5)

End Sub

Private Sub MyMSI_MouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim zoom As Double = 1
    zoom = zoom / 3
    ' This time the zoom is reversed (1/3) although the pan 
    ' remains the same - zoom back out from the middle.
    Me.MyMSI.ZoomAboutLogicalPoint(zoom, 0.5, 0.5)

End Sub
private void MyMSI_ImageOpenSucceeded(object sender, RoutedEventArgs e)
{
    // Turn the animations off when the image first loads. This avoids
    // the default behavior of the image initially zooming into view. 
    // However, you will probably want to turn the animations on later
    // so that the user will have animations when they pan and zoom.
    MyMSI.UseSprings = false;

}

private void MyMSI_MouseEnter(object sender, MouseEventArgs e)
{
    if (MyMSI.UseSprings == false)
    {
        MyMSI.UseSprings = true;
    }

    // The ZoomAboutLogicalPoint method allows you to zoom and pan
    // in the same step. The first parameter is the zoom (3x) and the
    // second and third parameters are the respective x and y coordinates
    // of the logical point to zoom around.
    this.MyMSI.ZoomAboutLogicalPoint(3, .5, .5);

}

private void MyMSI_MouseLeave(object sender, MouseEventArgs e)
{
    double zoom = 1;
    zoom = zoom / 3;
    // This time the zoom is reversed (1/3) although the pan 
    // remains the same - zoom back out from the middle.
    this.MyMSI.ZoomAboutLogicalPoint(zoom, .5, .5);

}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.