Declare a DictionaryEntry in XAML


I am attempting to build a Dictionary in XAML but I'm having a few issues.
I have tried to use ArrayList and adding DictionaryEntry but the when this value is retrieved the dictionary Entry give an error
<collections:ArrayList x:Key="GroupConversions" >
<collections:DictionaryEntry Key="bla" Value ="bla"/>

I have also tried a HashTable but I cannot even add values to this in XAML as it doesn't contain a ContentPropertyAttribute.
<collections:HashTable x:Key="GroupConversions" >
<collections:DictionaryEntry Key="bla" Value ="bla"/>

I know this is easy enough to create in the ViewModel or the code behind, but I would like to do this in XAML only.

Thanks for the help



  • ColeXColeX Member, Xamarin Team Xamurai

    It's not a good idea to declare a data type in XAML , it goes against the MVVM design .

    AFAIK, we can only access with ResourceDictionary.

    For example :

            <x:String x:Key="a">abc</x:String>
            <x:String x:Key="b">abc</x:String>
            <x:String x:Key="c">abc</x:String>
            <x:String x:Key="d">abc</x:String>
  • DRAirey1DRAirey1 Member ✭✭

    This is a legitimate question. I have used dictionaries to translate between enums in a View Model, and actual bitmaps in the View. It's a very basic design pattern for MVVM, but XAMARIN seems to be brain-dead. The XAML syntax recognizes IDictionaries, but gives a 'Sequence contains no matching element' error when you try to use them.

Sign In or Register to comment.