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

5 posts, 0 answers
  1. yu
    yu avatar
    3 posts
    Member since:
    Apr 2017

    Posted 15 May Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    774 posts

    Posted 17 May Link to this post

    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.
  3. yu
    yu avatar
    3 posts
    Member since:
    Apr 2017

    Posted 17 May in reply to Stefan Link to this post

    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

  4. Stefan
    Admin
    Stefan avatar
    774 posts

    Posted 22 May Link to this post

    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.
  5. yu
    yu avatar
    3 posts
    Member since:
    Apr 2017

    Posted 22 May in reply to Stefan Link to this post

    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. 

Back to Top