1

I have some quite complex content behind several tabs. I'd like to force the layout to happen at application startup rather than lazily as the user clicks a tab for the first time. The delay is about a second or two per tab, and it's a bit embarrassing!

Edit: I think the problem is that only the selected tab's content control is in the visual tree. Calling ApplyTemplate of the HeaderedContentControl didn't make any difference.

James L
  • 16,456
  • 10
  • 53
  • 70
  • are you 100% sure that the UI is causing the delay? – Federico Berasategui Oct 16 '13 at 14:12
  • is your UI really that large? Can you post some sample XAML? Are you sure there are not any virtualization issues there? I've never seen such a delay coming specifically from the Visual Tree. – Federico Berasategui Oct 16 '13 at 14:57
  • @HighCore it really is. 2/3rds of the time is measuring, the remaining is arrangement. What's happening is the tab control is adding and removing the content to the visual tree. The first time it does this, it takes an age. Subsequent times are fine. So I'd like to find out what it's doing the first time and trigger it manually – James L Oct 16 '13 at 19:48
  • I'd really like to see at least part of the offending XAML, or at least a screenshot... I seriously doubt that unless your UI is really HUGE (and by huge I mean in the order of the tens of thousands of UI Elements) it's causing this delay. – Federico Berasategui Oct 16 '13 at 19:50

1 Answers1

1

Does this link help you?

wpf force to build visual tree

Basically it says to use ApplyTemplate on the ItemsControl...I guess that for the tabs you should do it for each TabItem.

There's also another technique used in this site: http://xcalibur37.wordpress.com/2012/07/12/make-your-tabcontrol-preload-in-wpf-silverlight/

Here he creates a kind of preloader for each tab. It's for silverlight but I think it can be applied to WPF.

Hope it helps out :)

Community
  • 1
  • 1
sexta13
  • 1,558
  • 1
  • 11
  • 19