I’m some application and i would like to bind some textboxes and chekcboxes to value field of Dictionary(Enum, string). Is this possible and how can I do that?
In xaml code I have something like this – it is working for Dictionary with string as a key, but it cannot correctly bind to key with enum
<dxe:TextEdit EditValue="{Binding Properties[PrimaryAddress], Mode=TwoWay}" />
<dxe:TextEdit EditValue="{Binding Properties[SecondaryAddress], Mode=TwoWay}" />
<dxe:CheckEdit EditValue="{Binding Properties[UsePrimaryAddress], Mode=TwoWay}" />
.. and here is what I have in Enum
public enum MyEnum
{
PrimaryAddress,
SecondaryAddress,
UsePrimaryAddress
}
In ViewModel dictionary is defined as:
public Dictionary<MyEnum, string> Properties
I have found solution for combobox with enum values but this does not apply to my case.
Any advice?
You have to set appropriate type for indexer’s parameter in binding expression.
View model:
XAML:
Code-behind:
For more info, see “Binding Path Syntax“.