Preload tabbed ToolWindows

Docking/MDI for WPF Forum

Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Version: 16.1.0630
Avatar

I have a DockSite with its ToolItemsSource bound to a collection of view models.

When I populate certain properties on my ViewModel the ToolItemsSource changes and is populated with a new collection of VMs.

When I populate those VMs, i need each tab to load its content in the background, even if its not selected.

This is because each tab contains a Web browser control, which doesn't load until it is attached to the view, which doesn't happen until a tab is selected.

I've tried automatically selecting each tab both through the docksite and through the view model, but neither seem to preload the tabs correctly.

 

Is there any way to do this?

My DockSite is setup with a TabbedMdiHost if that helps.

Comments (9)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi James,

This sounds tricky since based on what you said, the WebBrowser only loads if fully loaded into a view.  Other than what you tried, perhaps you could put the WebBrowser within your main UI Window offscreen (translated to negative coordinates so it doesn't show?) and then as soon as it starts loading there, reparent it over into the related tool window and do the same process with the rest of them?


Actipro Software Support

Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Avatar

Would it be possible to change the construction of hte panel that hosts the docked window content so that It could host all docked windows?

With the regular WPF TabControl, I've done this by making the content Panel a Grid, with a trigger that changes the Panel.ZIndex value of each contained element upon tab selection.

I was hoping I could do the same with the Docking Windows, but I'm not sure what templates I need to modify in order to make that happen.

Posted 8 years ago by Stefan Koell
Avatar

I seem to have the same issue. Would be interested if there's a workaround.

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi James,

It might be possible to do that.  Our ToolWindowContainer and TabbedMdiContainer controls both host inherited variations of AdvancedTabControl (ToolWindowContainerTabControl and TabbedMdiContainerTabControl respectively).  AdvancedTabControl inherits the native WPF TabControl. 

If you make implicit Styles that target ToolWindowContainerTabControl and TabbedMdiContainerTabControl and change their Templates perhaps like you did in the past for the WPF TabControl, you could probably achieve what you are trying to do.


Actipro Software Support

Answer - Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Avatar

Okay, so this strategy does work.

If you request the templates from ActiPro, there is a file Docking.xaml which contains the relevant templates to solve this problem.

There are a few layers you need to deal with to ensure it works correctly, I only needed to support the ToolWindowContainer setup, but the same changes can probably be effectively applied to the TabbedMdi setup.

Copy the following out of Docking.xaml into your own ResourceDictionary;

AdvancedTabControlStyle Template Setter

    We just want to copy the template setter.

 
 First, Make an implicit template for ToolWindowContainer
  • Add a Setter to set the TabControlStyle property to your ToolWindowContainerTabControl style.
Now create a new style whos TargetType is ToolWindowContainerTabControl
  1. Paste the setter from AdvancedTabControlStyle into your ToolWindowContainerTabControl style.
  2. Find the HighlightBorder, contained in that is a ContentPresenter, this is the content that presents the selected tab.
  3. Replace the ContentPresenter with a ListBox (specifically a listbox, an ItemsControl will not work)
  4. On the ListBox add TemplateBindings to the ItemsSource and the SelectedItem properties to the template properties of the same names.
  5. Use the Margin Template Binding on the ContentPresenter
  6. Migrate the TemplateBindings for SelectedContentTemplate and SelectedContentTemplateSelector to ItemTemplate and ItemTemplateSelected respectively.
  7. You'll need to setup a Custom ItemContainer Style.  You can add more, but you'll need the next few items specifically.
  • A setter for Visibility set to Hidden
  • A trigger for IsSelected with a Value of true, which has a setter for Visibility set to Visible
  • Add a setter to the trigger to set the Background to transparent so you don't have any unexpected rendering.

 

Edit: update with below advice, as well as fixed the horribly erronous directions.

[Modified 8 years ago]

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi James,

You make a good point there.  Since the ToolWindowContainer template sets the ToolWindowContainerTabControl's Style property, simply adding an implicit Style for that type in your application resources won't work.  That being said, you can simply make an implicit Style targeting ToolWindowContainer and set its TabControlStyle property to your custom ToolWindowContainerTabControl style.  That is what gets bound down to the ToolWindowContainerTabControl.Style property.


Actipro Software Support

Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Avatar

Ah thats a much cleaner solution than carrying over a whole new style!

Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Avatar

There are a few errors in my explanation, I'll resolve them.

Posted 8 years ago by James LaPenn - Senior Software Engineer, Loomis, Sayles, Company, L.P.
Avatar

I just wanted to update this to ping anyone who was interested in the solution for this.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.