开发者

wpf: usercontrol vs. customcontrol performance issue

开发者 https://www.devze.com 2022-12-24 12:18 出处:网络
Which one is better from performance view user control or custom control? Right now I am using user control and In a specific scenario, I am creating around 200(approx.) different instances of this co

Which one is better from performance view user control or custom control? Right now I am using user control and In a specific scenario, I am creating around 200(approx.) different instances of this control but it is bit slow while loading and I need to wait atlest 20-30 second to complete 开发者_StackOverflow中文版the operation. What should I do to increase the performance?

Edit:

The scenario is: In my Window, I have a TreeView, each item of this represents different user-defined types, So I have defined DataTemplate for each type. These DataTemplates are using user-controls and these usercontrols are binded with properties of user-defined types. As simple, TreeView maps a Hierarchical Data Structure of user-defined types. Now I read from Xml and create the Heirarchical structure and assign it to TreeView and it takes a lot of time to load. Any help?


I have an application that is loading around 500 hundred small controls. We originally built these as user controls, but loading the baml seems to cause the controls to load slow (each one is really fast, but when we get around 300, the total of all of them together seems to add up). The user controls also seem to use up a good amount of memory. We switched these to custom controls and the app launches almost twice as fast and takes up about 1/3 the ram. Not saying this will always be the case, but custom controls made a big difference for us.


FYI: Here's a link on using a VirtualizingPanel with the TreeView: http://msdn.microsoft.com/en-us/library/cc716882.aspx


Make sure to SuspendLayout while adding controls en masse. Try to completely configure the control before adding it to any container.


Here is the follow-up article to my issues with WPFs Virtualizing Stack Panel and TreeView. I hope this helps you.

http://lucisferre.net/2010/04/21/virtualizing-stack-panel-wpf-part-duex/

Long story short: It is possible to do the navigation with the current VSP, but it is a bit of a hack. The current VSP design needs a rework, as the way it currently virtualizes the View breaks the coupling between the View and ViewModel which, in turn, breaks the whole concept of MVVM.


I worked at Microsoft and was not allowed to use the UserControl because of its poor performance. We always created controls in C#. Not sure about the performance of DataTemplates, but am interested in knowing if it is better. I suspect that it is.

0

精彩评论

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