In WPF, some controls trigger unload more than once, a bit baffling ~
Multiple triggers for unload
TabControl's content, I set it this way:
In TabItem Cachesettingview, listen for the loaded/unloaded event.
- Triggers a loaded when the window is loaded
- Uncheck TabItem and close the window to trigger a unloaded
- However, if the appropriate tab is selected and the Cachesettingview content is displayed, then closing the window will trigger both Unloaded
Cause: two times unloaded, respectively, is triggered by TabControl and TabItem.
It is important to note that switching tab also causes frequent calls to TabItem control loaded and unload events
touch many times unload details, you can refer to the colleague of the Big Brother's blog "Why Unload twice"
Unload Multiple triggering solutions
How to solve? You can discard TabControl, add a ListBox rewrite style template, or modify it as follows:
The control content on the right is displayed, directly bound to the selected state of TabItem. The plan is very simple, just for Mark, later on their own convenient query ~
Of course, you can also change the tabitem to RadioButton etc.
WPF TabControl Unload Two-time solution