How to bind to a specific item in a collection?

How to link let say TextBox.Text to myDictionary["testElement"] ?

+4
source share
2 answers

Have you tried removing quotes around testElement ? If the key is a string that should work.

From MSDN :

Property indexers can be indicated in square brackets following the name of the property in which the index is applied. For example, the sentence Path = ShoppingCart [0] establishes a binding to the index, which corresponds to how the internal indexing of your property processes the letter string "0". Several indexers are also supported.

[...]

Inside indexers, you can have several indexer options, separated by commas (,). The type of each parameter can be specified by parentheses. For example, you can have Path = "[(sys: Int32) 42, (sys: Int32) 24]", where sys maps to the System namespace.

+4
source

The best way is to use a derivative of the IValueConvertor class. You are attached to the dictionary itself and set ConverterParameter = 'testElement', in your converter you get both the dictionary and the key and return what you need.

+2
source

All Articles