110,538
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="725">
<StackPanel Margin="16">
<StackPanel Margin="8">
<TextBlock Name="myTextBlock" Margin="4" Text="Hello, world" MouseDown="myTextBlock_MouseDown"/>
</StackPanel>
</StackPanel>
</Window>
private void myTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
GeneralTransform generalTransform1 = myTextBlock.TransformToAncestor(this);
Point currentPoint = generalTransform1.Transform(new Point(0, 0));
MessageBox.Show(currentPoint.X.ToString());
MessageBox.Show(currentPoint.Y.ToString());
}