Wednesday, October 7, 2009

Dictionary vs. KeyValuePair

A Dictionary is a collection of KeyValuePairs and same is the List of KeyValuePair also.

then whats the diff?

In case of dictionary, it takes cares of the fact that keys are unique through the collection.
while a list of keyvaluepair can have repaeting keys in the collection. There may be scenarios where you may have such specific requirements. Use accordingly.

WPF: String Formatting in xaml

String can be Formatted very easily in xaml.
To format a text that is to be displayed in a textblock, first bind the textblock with the field and then use StringFormat attribute of the textblock to format the value.
For example:

<TextBlock Text="{Binding Children.Count}"/>

If you want to insert braces surrounding this value:
<TextBlock Text="{Binding Children.Count, StringFormat='{}{0:(#)}'}"/>