我想在视口中返回鼠标单击的坐标。当我在视口内部单击时,它显示我的屏幕坐标(例如480,650),但我的视口的范围是(0,0)说(10,10)。如何获取鼠标点击视口坐标系的坐标。 我的xaml代码:
<Window x:Class="PathOptimization.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Geometries"
xmlns:tool3d="clr-namespace:_3DTools;assembly=3DTools"
Title="MainWindow" Height="350" Width="1000" WindowState="Maximized">
<Grid x:Name="grdView" >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Viewport3D x:Name="viewport" Grid.Column="1" MouseDown="button_MouseDown" Margin="0,35,0,0">
<ContainerUIElement3D>
<ModelUIElement3D >
..............................
</ModelUIElement3D>
</ContainerUIElement3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0,1,9"
LookDirection="0,0,-2"
UpDirection="0,1,0"/>
</Viewport3D.Camera>
</Viewport3D>
当我点击视口内的屏幕时,我得到了屏幕坐标。如何获取相对于视口的坐标。
private void button_MouseDown(object sender, MouseButtonEventArgs e)
{
Point pointToWindow = e.GetPosition(viewport);
Point pointToScreen = PointToScreen(pointToWindow);
double x = (pointToScreen.X);
double y = (pointToScreen.Y);
MessageBox.Show(x + "," + y);
}