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