开发者

Nested Control + Top, Left properties

开发者_开发百科I have a silverlight control c1 that contains another silverlight control c2.

When trying to execute the below code.

c1.c2.GetValue(Canvas.LeftProperty)
c1.c2.GetValue(Canvas.TopProperty)

The result is always 0. How can i get the Top and Left property for the inner control relative to the main canvas.


You can do the following:

var transform = c2.TransformToVisual(c1);
var relativePoint = transform.Transform(new Point(0, 0));
var c2left = c1.GetValue(Canvas.LeftProperty) + relativePoint.X
var c2top = c1.GetValue(Canvas.TopProperty) + relativePoint.Y
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜