I’m trying to bind to a Dictionary<Type,string> through xaml.
The problem is, the indexer [] in the Binding markup extension interprets it’s content as string. Is there some kind of ‘unescape-sequence’ for that case?
<TextBox Text="{Binding theDictionary[{x:Type ns:OnePrettyType}]}" />
(Binding doesn’t work because {x:Type ns:OnePrettyType} is being sent as string)
If the indexer has a specific type the conversion should be done automatically so this should work:
If you need an explicit interpretation you can try a “cast” like this:
(Where
sysis mapped to theSystemnamespace of course)That would be the theory but all of that won’t work. First of all if you use the
Bindingconstructor that takes a path the cast will be ignored as it uses a certain constructor ofPropertyPathin a certain way. Also you will get a binding error:You would need to make it construct the
PropertyPathvia the type converter by avoiding theBindingconstructor:Now this will most likely just throw an exception:
So there unfortunately is no default type conversion going on. You could then construct a
PropertyPathin XAML and make sure a type is passed in, but the class is not meant to be used in XAML and will throw an exception if you try, also very unfortunate.One workaround would be to create a markup extension which does the construction, e.g.
Which then can be used like this:
or like this