If your Image's XAML as follow:
<Border Grid.Row="1" Grid.Column="0"
BorderThickness="3"
BorderBrush="BlueViolet">
<Image x:Name="Image_Box"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Source="8.jpg"
Stretch="Uniform"
MouseMove="ImageBox_OnMouseMove"
/>
</Border>
Maybe the Image
control's width is double.Nan ,So we need to use ActualWidth
property. so the Code as follow:
private void ImageBox_OnMouseMove(object sender, MouseEventArgs e)
{
ImageSource imageSource = Image_Box.Source;
BitmapSource bitmapImage = (BitmapSource)imageSource;
TextBoxCursor_X.Text =( e.GetPosition(Image_Box).X * bitmapImage.PixelWidth / Image_Box.ActualWidth).ToString();
TextBoxCursor_Y.Text = (e.GetPosition(Image_Box).Y * bitmapImage.PixelHeight / Image_Box.ActualHeight).ToString();
}