Reputation: 1096
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: How can I know this position? Thanks.
Upvotes: 1
Views: 550
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