WPF TabControl Unload Two-time solution

Source: Internet
Author: User

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.

    1. Triggers a loaded when the window is loaded
    2. Uncheck TabItem and close the window to trigger a unloaded
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.