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 1037471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:51:20+00:00 2026-05-16T14:51:20+00:00

I have a TabControl that can be rearranged by dragging/dropping the tabs. The current

  • 0

I have a TabControl that can be rearranged by dragging/dropping the tabs. The current process removes an item from the list and adds it to a new location. I had some performance issues switching tabs because of how complex the tabs are, so found an alternative which stores the rendered tabs and reloads them when requested. My only problem with it is that when dragging/dropping tabs, it re-renders each tab and causes the same delay. Is there a way to simply Move the item in the collection instead of Adding/Removing it?

Or failing that, is there a way to cancel the addition/removal in the OnItemsChanged event during a drag/drop operation? The process affects the visual of the control, so I need to actually cancel the add/remove event if it was caused by a drag/drop operation (users can also add/remove tabs normally).

  • 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-16T14:51:21+00:00Added an answer on May 16, 2026 at 2:51 pm

    I ended up modifying my OnItemsChanged event to run the Remove code at a lower dispatcher priority then the Add code, so it gives the Add operation a chance to cancel the Remove one and reuse the TabItem’s ContentPresenter instead of rendering a new one.

    Original code I started with was obtained from here

    It basically stores the TabItem ContentPresenters so when switching tabs it uses a stored ContentPresenter instead of redrawing a new one. Here’s the modifications I made to OnItemsChanged to get the Drag/Drop to reuse an old item instead of redrawing a new one

    case NotifyCollectionChangedAction.Add:
    case NotifyCollectionChangedAction.Remove:
    
        // Search for recently deleted items caused by a Drag/Drop operation
        if (e.NewItems != null && _deletedObject != null)
        {
            foreach (var item in e.NewItems)
            {
                if (_deletedObject == item)
                {
                    // If the new item is the same as the recently deleted one (i.e. a drag/drop event)
                    // then cancel the deletion and reuse the ContentPresenter so it doesn't have to be 
                    // redrawn. We do need to link the presenter to the new item though (using the Tag)
                    ContentPresenter cp = FindChildContentPresenter(_deletedObject);
                    if (cp != null)
                    {
                        int index = _itemsHolder.Children.IndexOf(cp);
    
                        (_itemsHolder.Children[index] as ContentPresenter).Tag =
                            (item is TabItem) ? item : (this.ItemContainerGenerator.ContainerFromItem(item));
                    }
                    _deletedObject = null;
                }
            }
        }
    
        if (e.OldItems != null)
        {
            foreach (var item in e.OldItems)
            {
    
                _deletedObject = item;
    
                // We want to run this at a slightly later priority in case this
                // is a drag/drop operation so that we can reuse the template
                // Render is good since a normal Removal of an item will run prior to adding a new one
                this.Dispatcher.BeginInvoke(DispatcherPriority.Render,
                    new Action(delegate()
                {
                    if (_deletedObject != null)
                    {
                        ContentPresenter cp = FindChildContentPresenter(_deletedObject);
                        if (cp != null)
                        {
                            this._itemsHolder.Children.Remove(cp);
                        }
                    }
                }
                ));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the selected item in WPF-TabControl that could be reproduced
I have a form that displays file information in a TabControl, and I'd like
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
Hey. I have a tabcontrol that is bound to an observable collection. I've tried
I have a WPF TabControl that has a couple of buttons in the TabItem
This is my scenario... I have a winForm tabControl that has a variety of
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a TabControl and each Tab can contain the same UI but with
I have a TabControl within a TabControl. I want the outer TabControl to show
I have derived a TabControl with the express purpose of enabling double buffering, except

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.