Application.Current.Windows.Cast<Window>() returns nul
本文关键字:returns nul gt Window Cast Current lt Application Windows | 更新日期: 2023-09-27 18:36:38
我正在尝试从另一个窗口访问一些控件(ScrollViewer和Grid)。我试过这个:
var reportW = Application.Current.Windows.Cast<Window>().SingleOrDefault(window => window is ReportWindow) as ReportWindow;
ScrollViewer myScrollViewer = reportW.testScrollViewer;
Grid myGrid = reportW.Grd;
问题是报告W是所有null
。我的方法有问题吗,还有其他方法可以从另一个窗口访问控件吗?
试试这个:
ReportWindow reportW = Application.Current.Windows.OfType<ReportWindow>().
SingleOrDefault();