I’m attempting to databind to an entry in a dictionary where the key is the enum. I’ve consulted this question, but the answer doesn’t work for me. Here are the non-boilerplate parts of my code:
SomePage.xaml:
<!-- Here I try all the ways I can think of. None of them produce any text -->
<TextBlock Text="{Binding Data[0]}" />
<TextBlock Text="{Binding Data[EnumValueA]}" />
<TextBlock Text="{Binding Data[SomeEnum.EnumValueA]}" />
<TextBlock Text="{Binding Data[(local:SomeEnum)EnumValueA]}" />
<TextBlock Text="{Binding Data[(local:SomeEnum)SomeEnum.EnumValueA]}" />
SomePage.xaml.cs:
public SomePage() {
DataContext = new SomeVM();
InitializeComponent();
}
SomeVM.cs:
public enum SomeEnum {
EnumValueA, EnumValueB
}
public class SomeVM {
public Dictionary<SomeEnum, int> Data { get; private set; }
public SomeVM() {
Data = new Dictionary<SomeEnum, int> {
{SomeEnum.EnumValueA, 1337}
};
}
}
Why does this databinding not work?
It is not possible. See http://msdn.microsoft.com/en-us/library/cc645024(v=vs.95).aspx#indexdata