Content is only loaded when window is visible

Docking/MDI for WPF Forum

Posted 6 months ago by Dirk Zellerfeld
Version: 21.1.1
Platform: .NET 5.0
Environment: Windows 10 (64-bit)
Avatar

I have multiple document and tool windows and all have the new WebView2 control as content. When I start the app I create these windows in background (there is a grid on top of the docksite hiding it) and I call the Activate() method on each of these windows.Then I set the docksite to be visible by hiding this grid.

On all visible windows the content is immediately there but on all windows/tabs in background as soon as I manually click on them to show them up, the WebView2 control on it starts loading. Just like they would lazy load. I've searched the forum and on several other topics it was told to call the Activate() method but I'm doing this. But it only works for the LAST window in each (split/toolwindow)container.

For example I have a toolwindow container with tool window A and B. In code I call A.Activate() and then B.Activate(). Content on B is immediately there but on A its not. If I change my code to call B.Activate() first and then A.Activate(), the content on A is immediately there but not on B.

Is there anything else than Activate() method to ensure the content is not lazy loaded?

[Modified 6 months ago]

Comments (2)

Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dirk,

The docking window containers have docking:AdvancedTabControl instances in them that work the same way as native WPF TabControl, where only the selected tab's content is visible in a ContentPresenter at any given time.  Otherwise if all child controls were loaded for all tabs into the visual tree, it could make window resize operations dramatically slower due to the many times more elements in the visual tree.

Based on what you are describing it sounds like your Activate() calls are switching tabs, but the tab switches are all complete by the time the native WPF layout logic dispatches.  As a test of this, you might try calling Activate(), and then UpdateLayout() after each Activate() call.  UpdateLayout() generally will force the templates to be applied and measure/arrange cycles to run.  This may solve the problem, but can cause a slowdown of your load since more layout cycles are being executed.

Even if that works for you, it's not really a good practice to have to do this running through and activating all docking windows.  Other possible options might be:

1) Check Microsoft's WebView2's docs and/or GitHub repo to see if there is a way you can force their control to load a web page prior to the WebView2 being realized in the visual tree.

or

2) Create a Panel in your Window that is shifted out of view (like in negative coordinates via a RenderTransform).  Load all your WebView2 instances into that so that they enter the visual tree before the docking window layout is loaded.  Call UpdateLayout() on that panel and that hopefully triggers them all to load.  Then move all those controls back into appropriate docking windows as they are opened.


Actipro Software Support

Posted 6 months ago by Dirk Zellerfeld
Avatar

Loading time is not a problem since we have a loading indicator anyway. I've added UpdateLayout() on all of them, which causes a delay of a second only and it seems to fix the problem.

The latest build of this product (v21.1.3) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.