0

I have Tab Control, with two tabs, and each tab contains a UserControl, the UserControls have Visual States defined along with Transitions.

The issue, that I'd like to get around, is that every time I change active tabs, the Visual State Transition storyboard runs, even when the control should already be in a state, and not need to be changed.

I've tracked this to the fact that changing tabs, causes the Constructor for all child UserControls in the newly visible tab to run. Is there a way to avoid this?

Nate
  • 30,286
  • 23
  • 113
  • 184

2 Answers2

2

This happens because every time you change a tab item the contents of the previous tabs are unloaded from the VisualTree.There is a lot of discussions on this subject here itself.Go through the links below

WPF TabControl - Preventing Unload on Tab Change?

http://www.hardcodet.net/2008/01/wpf-loaded-event-fired-repeatedly

http://eric.burke.name/dotnetmania/2009/04/26/22.09.28

How to preserve control state within tab items in a TabControl

Hope this helps

Community
  • 1
  • 1
biju
  • 17,554
  • 10
  • 59
  • 95
0

Turns out that because I binding the Content of the Tab it was unloading and reloading. Changing over to StaticResources and using DataContext fixed the issue in my case.

Nate
  • 30,286
  • 23
  • 113
  • 184