We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
Where do you locate your convertors? do you put them in the Window.Resources section? or in the UserControl they are being used for? Neither of these options is good. You should put it in the App.Xaml file and here is why:
Lets look at the following example:
Here is our Window:
In the Window Code Behind we create a list filled with some DateTime objects:
As you can see The template holds a UserControl, here is the UserControl Code:
The converter converts the DateTime to universal time:
I have also added a Trace Print in the Converter Constructor so we can see how many time it is called:
We have 6 Items in the list and this is what we got in the Visual Studio Output window:
6 “Converter Created” Prints in the output, Now Imagine you had 1000 Items in that list…
The Window will probably be created only once, but you can’t move the Converter and locate it in the Window, the UserControl won’t “see” it there. Your only option is to put in in App.Xaml.
Once moved to the App.Xaml file we get only one “Converter Created” Line in the Output, which means that only one instance of the Converter was created.
Tags :App.XamlBindingBinding ConverterConvertConverterDateTimeItemsValue ConverterWindow
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd