tags:

views:

18

answers:

2

I know I can declare an array of string in XAML like this:

<x:Array Type="{x:Type System:String}">
   <System:String> first </System:String>
   <System:String> second </System:String>
   <System:String> third </System:String>
</x:Array>

How can I declare an array of System.Collections.Specialized.StringDictionary in XAML

<x:Array Type="{x:Type Specialized:StringDictionary}">
    <Specialized:StringDictionary>
        (((what do I put here?)))
    </Specialized:StringDictionary>
</x:Array>

Thanks!

A: 

Nothing. You can't do that in XAML.

There is only one way to populate a StringDictionary: call it's Add(string,string) method. XAML does not allow to call methods. Only assign properties, and, as a special case, populate collections that implement ICollection<T>, which StringDictionary doesn't.

Fyodor Soikin
A: 

No built in way to support it but two options to get you close.

If you are on .NET 4 and are NOT compiling your XAML (highly unlikely) you can do something like this

http://blogs.windowsclient.net/rob_relyea/archive/2009/06/01/xaml-using-generic-types-in-xaml-2009.aspx

Again, this is really not a viable solution for most but it is possible.

More than likely you will want to create a custom markup extension to support generic collection initialization. Something like this:

http://blogs.msdn.com/b/mikehillberg/archive/2006/10/06/limitedgenericssupportinxaml.aspx

adapt his last solution to include key and value and it should get where you want, sort of

Foovanadil