views:

40

answers:

2

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 there any other method to get the Distance bettwen ChildWindow and ParantWindow?

Thanks,

Subhe

A: 

Experiment with PointToScreen and PointFromScreen methods of your windows.

PointFromScreen article

PointToScreen article

Eugene Cheverda
Unable to get PointFromScreen and PointToScreen Method for ChildWindow. I am currently using SL.
Subhen
A: 

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

AnthonyWJones
Thanks Anthony but I am Unable to get the Method Descendents() for my ChildWindow myChildWindow
Subhen
@Subhen: You have included the above class in your project and you understand how `extension` methods work?
AnthonyWJones