Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a large number of styles defined for my grid (cell colors based on state, etc.). Right now I use DataTriggers to set the appropriate colors. I am looking to improve the performance of my app and was thinking that the large number of styles may be causing a slow down (due to the data changing constantly and the styles needing to be recalculated/refreshed). Is it better to use data binding with converters instead of DataTriggers?

If the goal can be achieved using either method, is there any performance difference? I am not familiar with what is going on behind the scenes so I can't be sure.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
949 views
Welcome To Ask or Share your Answers For Others

1 Answer

In this episode of the Hanselminutes podcast, guest Laurent Bugnion (creator of MVVM Light) describes that there is a performance hit associated with using converters. He indicates that it is almost always negligible in desktop applications, but that in WP7 applications, it is recommended that viewmodels expose things like brushes directly, rather than relying heavily on converters, especially if dealing with list virtualization, in which case scrolling will cause many invocations of the conversion.

It is possible that a similar thing is occurring in your scenario, just given the volume of triggers (or conversions if you made that switch).

As a proof of concept, you might consider wrapping your view-model in a "WPF Viewmodel," that exposes the colors and other WPF-specific values themselves, rather than some value from which the colors can be determined by the runtime invoking triggers and IValueConverters. You'll then be able to bind directly to that, and use neither triggers nor converters. I'd be interested to hear the results.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...