Issue when using custom class with indexes in data binding
Posted: 14 Apr 2015, 15:07
I have in my application (Unity) a class for testing indexing in DataBindings in XAML:
That is used as a DataContext for a XAML with the contents:
When I run this as a WPF-application in Blend, all three TextBlock behave as expected:

Using Noesis+Unity, however, the final TextBlock (the one using my custom indexer) ends up empty. How come? Am I missing something?
Code: Select all
public class IndexTest
{
public IndexTest()
{
_list.Add("foobar");
_dict.Add("foo", "bar");
}
private List<string> _list = new List<string>();
private Dictionary<string, string> _dict = new Dictionary<string, string>();
private Lexicon _lex = new Lexicon();
public List<string> List { get { return _list; } }
public Dictionary<string, string> Dict { get { return _dict; } }
public Lexicon Lex { get { return _lex; } }
//Custom class with indexer.
public class Lexicon
{
public string this[string arg]
{
get
{
var str = "foo " + arg;
return str;
}
}
}
}Code: Select all
<StackPanel>
<TextBlock Text="{Binding List[0]}"/>
<TextBlock Text="{Binding Dict[foo]}"/>
<TextBlock Text="{Binding Lex[foo]}"/>
</StackPanel>
Using Noesis+Unity, however, the final TextBlock (the one using my custom indexer) ends up empty. How come? Am I missing something?