I had a tab control where each tab item was a custom made user control. The issue there was whenever the program would launch, each individual control would be initialized and loaded. Then, when switching to the tab, it would have to reload again.
I've since changed how the tab items are loaded as shown below. This prevents the user controls from initializing and loading until they're clicked on (which is preferred):
<TabControl>
<TabItem>
<TabItem.ContentTemplate>
<DataTemplate>
<local:ctlHome />
</DataTemplate>
</TabItem.ContentTemplate>
</TabItem>
<TabItem>
<TabItem.ContentTemplate>
<DataTemplate>
<local:ctlTwo />
</DataTemplate>
</TabItem.ContentTemplate>
</TabItem>
...
</TabControl>
When I first rolled this out, every time I would switch to a new tab, it would call the constructor -> Unload the previous tab -> Load the new tab, which is great. It would only call the constructor once, and whenever I re-selected the tab, it would just unload -> load as expected.
Now, every time I select a tab, it calls the constructor and re-initializes the entire control. I'm not sure why it's no longer keeping the tab in memory.
Is there any way I can keep the user controls in memory once they've initialized using this method?