tags:

views:

19

answers:

1

I have some paths that are not inside any canvas, and I want to know how to get their X and Y position to create animations based on it.

<Grid x:Name="LayoutRoot" Width="640" Height="480">
        <Image Source="SC.png" Stretch="Fill" Width="640" Height="480" d:LayoutOverrides="HorizontalAlignment"/>

        <Path x:Name="but77" DataContext="77" MouseLeftButtonDown="MapClick" MouseEnter="MouseOver" MouseLeave="MouseOut" Fill="#FF2400FF" Stretch="Fill" Stroke="Black" Height="17.5" HorizontalAlignment="Right" Margin="0,104.875,68.125,0" VerticalAlignment="Top" Width="17.875" UseLayoutRounding="False" Data="M555,105.375 L554.5,121.75 L571,121.875 L571.375,105.5 z" Opacity="0"/>
        <Path x:Name="but51" DataContext="51" MouseLeftButtonDown="MapClick" MouseEnter="MouseOver" MouseLeave="MouseOut" Fill="#FF2400FF" Stretch="Fill" Stroke="Black" Height="17.5" HorizontalAlignment="Right" Margin="0,164.125,70.375,0" VerticalAlignment="Top" Width="17.875" Opacity="0" UseLayoutRounding="False" Data="M555,105.375 L554.5,121.75 L571,121.875 L571.375,105.5 z"/>
        <Path x:Name="but50" DataContext="50" MouseLeftButtonDown="MapClick" MouseEnter="MouseOver" MouseLeave="MouseOut" Fill="#FF2400FF" Stretch="Fill" Stroke="Black" Height="17.5" HorizontalAlignment="Right" Margin="0,0,70.375,178.375" VerticalAlignment="Bottom" Width="17.875" Opacity="0" UseLayoutRounding="False" Data="M555,105.375 L554.5,121.75 L571,121.875 L571.375,105.5 z"/>
        <Path x:Name="but82" DataContext="82" MouseLeftButtonDown="MapClick" MouseEnter="MouseOver" MouseLeave="MouseOut" Fill="#FF2400FF" Stretch="Fill" Stroke="Black" Height="17.5" HorizontalAlignment="Right" Margin="0,0,78.75,156.875" VerticalAlignment="Bottom" Width="17.875" Opacity="0" UseLayoutRounding="False" Data="M555,105.375 L554.5,121.75 L571,121.875 L571.375,105.5 z"/>

</Grid>
+3  A: 

The tool you need is the TransformToVisual method which is provided by all UIElement derivatives including Path. To find the X,Y position of one of your paths relative to the containing Grid use:-

 GeneralTransform gt = but77.TransformToVisual(LayoutRoot);
 Point but77Position = gt.Transform(new Point(0,0));
AnthonyWJones