2013-02-02 22 views
0

我想用下面的代码Application.current.mainwindow childwindow替代

Point point1 = pwImages.ElementAt(0).TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0)); 

然而,Application.Current.MainWindow未设置为调用此代码的窗口,因为主窗口是称为窗口App.xaml中。除了Application.Current.MainWindow还有我可以使用的替代方法吗?或者我可以将Application.Current.MainWindow重置为当前窗口吗?

回答

0

好吧,如果我发现我需要循环浏览子窗口列表以查找我正在查找的窗口并将其分配给一个变量。

Window myWindow; 
    foreach (Window objWindow in Application.Current.Windows) 
     { 
      if (objWindow.ToString().Equals("NameOfChildWindow")) 
      { 
       myWindow = objWindow; 
      } 
     } 

然后我就可以用objWindow作为产权置换

Point point1 = pwImages.ElementAt(0).TransformToAncestor(myWindow).Transform(new Point(0, 0));