This is a migrated thread and some comments may be shown as answers.

Can't get correct window everytime when pop up the child windows

4 Answers 187 Views
Window
This is a migrated thread and some comments may be shown as answers.
yu
Top achievements
Rank 1
yu asked on 15 May 2017, 07:46 AM

Hi all,

     I am a new in WPF. And, I haven't found the answer after searching the forum.

How can I find the child windows because only get WpfApplication.MainWindow and WpfApplication.Windows.Count=1 sometimes?

Then, I try to call  some refresh  or update functions as follows

wpfApplication.MainWindow.VisualTree.Refresh();

wpfApplication.MainWindow.VisualTree.Root.Refresh();

wpfApplication.MainWindow.UpdateInterHostLinks();                

wpfApplication.MainWindow.ContentWindow.RefreshChildren();              

wpfApplication.MainWindow.RefreshVisualTrees();              

wpfApplication.MainWindow.ContentWindow.Update();            

wpfApplication.MainWindow.Find.RefreshRoot();

However, it doesn't work. How can I get the child window every time? Many thanks

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 May 2017, 11:17 AM
Hello Yu,

You should be able to achieve this by accessing the WindowsCollection of the application. Please, check the following code snippet.
System.Windows.Application.Current.Windows;

You can also check out this StackOverflow thread where the topic is also discussed.

I hope this helps.

Best Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
yu
Top achievements
Rank 1
answered on 17 May 2017, 12:51 PM

Hi Stefan X1,

     I got exception from System.Windows.Application.Current.Windows because the value is null. Then, I'd like ask you how to use it properly? Could you please provide the sample code? Btw, what's the different between WindowsCollection in system.windows and  ArtOfTest.Common.Win32? Many thanks

0
Stefan
Telerik team
answered on 22 May 2017, 12:23 PM
Hi Yu,

Though I am not completely sure why the collection is null on your end, I suggest you verifying that it is accessed after the Application object is created. As this topic is general and is not directly related to the UI for WPF suite, I suggest you reviewing the WindowCollection MSDN topic and the Get all open WPF Windows StackOverflow thread as well.

Best Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
yu
Top achievements
Rank 1
answered on 22 May 2017, 06:30 PM

Hi Stefan X1,

     Thanks for replying. I found the indirect way to fix the problem when only get wpfApplication.MainWindow and WpfApplication.Windows.Count ==1. In my case, I still can find the items of the child window when only get main window Wpfwindow.

I use the method find.AllByAutomationId(id), then choose the newest item. However, I find the interesting thing in this case.

When wpfApplication.Windows.Count > 1 and get child window, the item position is different than only get main window.

Thanks for your information. I'll try it by System.Window. 

Tags
Window
Asked by
yu
Top achievements
Rank 1
Answers by
Stefan
Telerik team
yu
Top achievements
Rank 1
Share this question
or