Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:30:10+00:00 2026-05-23T18:30:10+00:00

I’m working on a WPF application with a tabbed MDI interface. Basically, the user

  • 0

I’m working on a WPF application with a tabbed MDI interface. Basically, the user clicks a menu item and this creates and adds a new tab. A new ‘MyUserControl’ is created and set to be the tab’s Content. Something like this:

    private void MenuItem_OnClick(object sender, RoutedEventArgs e)
    {
        this.TabControl.Items.Add(new TabItem() { Content = new MyUserControl() });
    }

MyUserControl is composed of several nested controls (approx. 8 controls). When this approach is wired up to the actual control, the performance is unacceptable.

Unless I’m losing my mind, I’ve noticed that the performance hit seems to be much less when declaring the tab and content in xaml ahead of time and simply toggling the tab item’s Visibility property:

    <Controls:TabControl x:Name="TabControl" Grid.Row="1">
        <Controls:TabControl.Items>
            <Controls:TabItem x:Name="MyTabItem" Visibility="Collapsed">
                <Controls:MyUserControl x:Name="MyUserControl" />
            </Controls:TabItem>
        </Controls:TabControl.Items>
    </Controls:TabControl>

and

    private void MenuItem_OnClick(object sender, RoutedEventArgs e)
    {
        this.MyTabItem.Visibility = Visibility.Visible;
    }

Can anyone explain this? Is it really more efficient to build the “visual tree” in xaml rather than programmatically? Or has the performance hit in my second approach just been moved to the overall form’s load instead of when the menu item is clicked as in the first approach?

The second approach definitely seems to perform much better. Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:30:10+00:00Added an answer on May 23, 2026 at 6:30 pm

    It is no more efficient to declare it it xaml. I think you are correct in thinking that the performance hit has been moved to the form load.

    If it is taking too long to load, maybe it is doing too much work in its constructor. See if you can minimize the work done during the loading of the control.

    Otherwise, if the problem is just the sheer amount of controls in the user control, maybe you could keep a fully loaded tab in memory until it is ready to be used. Once the user clicks the menu item, add it to the tabcontrol and then start loading a new one in a background thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an WPF application using the mvvm-light framework. I'm new to both
I'm working on a new WPF application and I'm trying to stay as close
I'm currently using PrintVisual() in a wpf application to do printing. This is working
I am working on a WPF application where the user can print multipage reports.
I am working on a new WPF application.. and I need to show a
I'm handling user input in a WPF application, working with RoutedEvents such as MouseDown
I'm working on a WPF application that sometimes exhibits odd problems and appears to
I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application
I am working on a WPF application which has a treeview that represents an
I'm working on a WPF application, and I'm structuring it using the MVVM pattern.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.