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).
I ended up modifying my
OnItemsChangedevent 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