6

I have TabControl bound directly to IEnumerable<ViewModelBase> (different ViewModels), rendered using DataTemplates. BUT when switching Tabs, one can se that TabItems are completely redrawed and it's soooo slow. Is it normal???

Cartesius00
  • 22,610
  • 41
  • 119
  • 191

2 Answers2

2

Is your data context truly exposing an IEnumerable<T> as the binding source? If so, I recommend you take a look at How Data Binding References are Resolved. This won't explicitly address the redraw issue, but if you expose your view models data source using a collection that supports the INotifyPropertyChanged interface such as ObservableCollection or a ICollectionView data source, you will get better binding and rendering performance.

On the redraw side of this issue, you should take a look at this Dr. WPF post. There is a proposed solution to the performance issue you are seeing, and to go one step further you would write a TabControl subsclass, and possibly use a VirtualizingStackPanel as the items source of the custom TabControl.

This article goes over the UI and data virtualization options you might try.

Oppositional
  • 10,961
  • 6
  • 48
  • 61
1

I would say yes, DataTemplates are blueprints of how to construct objects, so your TabControl might very well throw the old tab content and and create a new one if you switch tabs. Possibly this question is related.

(Even though people have complained before about the behaviour that the TabControl may actually reuse objects, i suppose this could depend on the underlying type of the items)

Community
  • 1
  • 1
H.B.
  • 142,212
  • 27
  • 297
  • 366