OT: Wpf TabControl SelectionChange unloading user controls.

OT: Wpf TabControl SelectionChange unloading user controls.

Old forum URL: forums.lhotka.net/forums/t/8874.aspx

richardb posted on Tuesday, May 04, 2010

Off Topic, but I'm hoping some fellow CSLA'ers have come across this.

My UI has a content area with tabs - I lsit records in one tab and then the user selects it they can edit the UI in one of the other tab's.  My edit forms consist of user controls.

The problem is, the WPF TabControl raises an Unload event to any user controls hosted in the tab when you select another tab.  This is causing me some UI pain as my usercontrols try and reload when you click back - some values disappear from conbo boxes (typically ones where they are based on another dropdown and I reset them in code-behind).  But essentially, the tab control is causing my user controls to unload when I don't want them to.

I've read that WPF likes to do this for performance reasons, but unloading your usercontrol from the visual tree causing the unload event to fire on the control, and then reloading it seems a bit of an assumption on it's part. 

Any ideas on how to stop it doing this?

Copyright (c) Marimer LLC