开发者

Nested Control + Top, Left properties

开发者 https://www.devze.com 2023-01-28 13:14 出处:网络
开发者_开发百科I have a silverlight control c1 that contains another silverlight control c2. When trying to execute the below code.

开发者_开发百科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

精彩评论

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