MultiScaleImage.ElementToLogicalPoint Method

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

Gets a point with logical coordinates (values between 0 and 1) from a point of the MultiScaleImage.

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

Syntax

'Declaration
Public Function ElementToLogicalPoint ( _
    elementPoint As Point _
) As Point
public Point ElementToLogicalPoint(
    Point elementPoint
)

Parameters

Return Value

Type: System.Windows.Point
The logical point translated from the elementPoint.

Remarks

Logical coordinates (also known as normalized coordinates) are between 0 and 1. This method takes a coordinate of the MultiScaleImage and returns the corresponding logical coordinate. For example, if the MultiScaleImage is 800 x 800 pixels, then the center point is at the coordinates of 400, 400. If you specified an elementPoint with coordinates of 400, 400, then this method would return a point with logical coordinates of 0.5, 0.5.

This method is useful in conjunction with the ZoomAboutLogicalPoint method, which only takes logical points. For example, you can use the ElementToLogicalPoint method to translate the current point the mouse pointer is over the MultiScaleSubImage into a logical point. Then. You can use that logical point in the ZoomAboutLogicalPoint method to zoom in on that point.

Examples

The following example shows how to zoom in on an image in the area that you click.

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 zoom As Double = 1
Private minzoom As Double = 0.00001
Private lastMouseLogicalPos As New Point()

Private Sub MyMSI_LeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim newzoom As Double = zoom / 1.3
    If newzoom < minzoom Then
        newzoom = minzoom
    End If
    lastMouseLogicalPos = e.GetPosition(Me.MyMSI)
    Dim logicalPoint As Point = Me.MyMSI.ElementToLogicalPoint(lastMouseLogicalPos)
    Me.MyMSI.ZoomAboutLogicalPoint(zoom / newzoom, logicalPoint.X, logicalPoint.Y)
    zoom = newzoom

End Sub
double zoom = 1;
double minzoom = 0.00001;
Point lastMouseLogicalPos = new Point();

private void MyMSI_LeftButtonDown(object sender, MouseButtonEventArgs e)
{
    double newzoom = zoom / 1.3;
    if (newzoom < minzoom) 
    { 
        newzoom = minzoom; 
    }
    lastMouseLogicalPos = e.GetPosition(this.MyMSI);
    Point logicalPoint = this.MyMSI.ElementToLogicalPoint(lastMouseLogicalPos);
    this.MyMSI.ZoomAboutLogicalPoint(zoom / newzoom, logicalPoint.X, logicalPoint.Y);
    zoom = newzoom;

}

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.