Stojdza
Stojdza

Reputation: 445

Application.Current.Windows.Cast<Window>() returns null

I'm trying to access some controls (ScrollViewer and Grid) from another window. I tried this:

var reportW = Application.Current.Windows.Cast<Window>().SingleOrDefault(window => window is ReportWindow) as ReportWindow;
ScrollViewer myScrollViewer = reportW.testScrollViewer;
Grid myGrid = reportW.Grd;

Problem is that reportW is allways null. Is something wrong with my approach and is there any other way to access controls from another window?

Upvotes: 0

Views: 865

Answers (1)

Sheridan
Sheridan

Reputation: 69959

Try this:

ReportWindow reportW = Application.Current.Windows.OfType<ReportWindow>().
SingleOrDefault();

Upvotes: 2

Related Questions