Std_Net
Std_Net

Reputation: 1096

In WP8 how to find position for a control relative to the second control

I have this page

<ViewportControl x:Name="Viewport" Grid.Row="0" Grid.RowSpan="2" SizeChanged="Viewport_SizeChanged">
     <Grid>
         <Image x:Name="Image1" Stretch="Uniform" CacheMode="BitmapCache"/>
         <Image x:Name="SeconImg" Grid.Row="0" Grid.RowSpan="2"/>
     </Grid>
</ViewportControl>

And I need to know position SeconImg relative Image1

Example: enter image description here How can I know this position? Thanks.

Upvotes: 1

Views: 550

Answers (1)

Romasz
Romasz

Reputation: 29792

You can get your relative position like this:

GeneralTransform myTransform = SeconImg.TransformToVisual(Image1);
Point relativePosition = myTransform.Transform(new Point(0, 0));

relativePosition has X and Y properties which you can read then.

TransformToVisual(UIElement visual) is a motehod of class UIElement, which allows you to read a position of any UIElement relative to other UIElement. For example you can read relative position to LayoutRoot (Grid).

Upvotes: 2

Related Questions