Application.current.mainwindow childwindow alternative
本文关键字:alternative childwindow mainwindow current Application | 更新日期: 2023-09-27 17:57:00
我想使用以下代码
Point point1 = pwImages.ElementAt(0).TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0));
但是,Application.Current.MainWindow 未设置为调用此代码的窗口,因为 mainWindow 是 app.xaml 调用的窗口。除了Application.Current.MainWindow之外,我是否可以在这里使用其他方法,或者我可以将Application.Current.MainWindow重置为我的当前窗口吗?
好的,
如果我发现我需要循环浏览我的子窗口列表以找到我正在寻找的窗口并将其分配给变量。
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));