开发者

How to get the Distance between ChildWindow and Parent Window?

Can we calculate the gap bettwen ChildWindow and ParentWidnow?

While I can Drag arround the ChildWindow there is a Distance from the Top and Left.

WHile I try to get the Distance using:

ChildWindow.Margin 

it is returning 0,0,0,0

Is开发者_如何学JAVA there any other method to get the Distance bettwen ChildWindow and ParantWindow?


A child window control actually occupies all the available space on the Silverlight content window. The first element in the template is the overlay Grid. Its this Grid which dims the "parent" window content and consumes all the mouse events that would otherwise go to "parent" content.

Inside the Overlay Grid is another Grid called "ContentRoot" which contains the border, chrome and your child content. Its this Grid that gets dragged around and will have a Margin.

Using this extension method:-

public static class VisualTreeEnumeration  
{  
   public static IEnumerable<DependencyObject> Descendents(this DependencyObject root)  
   {  
     int count = VisualTreeHelper.GetChildrenCount(root);  
     for (int i=0; i < count; i++)  
     {  
       var child = VisualTreeHelper.GetChild(root, i);  
       yield return child;  
       foreach (var descendent in Descendents(child))  
         yield return descendent;  
     }  
   }  
}

You could find the ContentRoot with:-

Grid contentRoot = myChildWindow.Descendents().OfType<Grid>().Where(g => g.Name == "ContentRoot");

From which you get the margin


Experiment with PointToScreen and PointFromScreen methods of your windows.

PointFromScreen article

PointToScreen article

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜