We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
In my previous post about WPF Binding Converters one of our readers (Thanks The Reddest) pointed our that a new converter instance is not created every time a call is made to the converter. I promised to test it again so here goes
I used the old converter code but added a static integer inside the converter to count the number of calls made to it. and then printed it out to the trace in the constructor.
Here is the code that was added to the converter:
If indeed the converter is created every time a call is made we should get several lines in the trace with an increasing number.
I also added a Button to the window that will change the datacontext and by that trigger a converter call by the Binding. I did not want to fill this article with all the lines from the trace but the only relevant line was the following:
This converter was Created 1 Times
Which means that Indeed the converter was created only once! and that makes that way of using converters the best way! No need for singletons and static classes! If you don’t remember I recommend reading the previous article and its comments.
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd