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???
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With