开发者

WPF slow when TabControl bound to ViewModels

I have TabControl bound directly to IEnumerable<ViewModelBase> (different ViewModels), rendered using DataTemplates. BUT when switching Tabs, one can se that TabItems are completely red开发者_如何学Crawed 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜