如何得到子窗口和父窗口之间的距离?

时间:2021-05-19 07:31:19

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

它返回0,0,0,0

Is there any other method to get the Distance bettwen ChildWindow and ParantWindow?

有没有其他的方法可以得到贝特温儿童窗口和帕拉纳温多的距离?

2 个解决方案

#1


1  

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.

子窗口控件实际上占用了Silverlight内容窗口上的所有可用空间。模板中的第一个元素是覆盖网格。它的这个网格改变了“父”窗口的内容,并消耗了所有的鼠标事件,否则这些事件就会变成“父”内容。

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.

在覆盖网格内是另一个叫做“ContentRoot”的网格,它包含边框、chrome和子内容。它的这个网格被拖拽,会有一个边距。

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:-

您可以找到ContentRoot with:-

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

From which you get the margin

从中你得到了利润。

#2


0  

Experiment with PointToScreen and PointFromScreen methods of your windows.

尝试使用windows的PointToScreen和PointFromScreen方法。

PointFromScreen article

PointFromScreen文章

PointToScreen article

PointToScreen文章

#1


1  

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.

子窗口控件实际上占用了Silverlight内容窗口上的所有可用空间。模板中的第一个元素是覆盖网格。它的这个网格改变了“父”窗口的内容,并消耗了所有的鼠标事件,否则这些事件就会变成“父”内容。

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.

在覆盖网格内是另一个叫做“ContentRoot”的网格,它包含边框、chrome和子内容。它的这个网格被拖拽,会有一个边距。

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:-

您可以找到ContentRoot with:-

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

From which you get the margin

从中你得到了利润。

#2


0  

Experiment with PointToScreen and PointFromScreen methods of your windows.

尝试使用windows的PointToScreen和PointFromScreen方法。

PointFromScreen article

PointFromScreen文章

PointToScreen article

PointToScreen文章