绑定到这个属性相当简单:
public Foo MyFoo {get; set;}
public class Foo
{
public object this[object key]
}
因为在 XAML 中您可以执行以下操作:
<Label Content="{Binding MyFoo["key"]}"/>
但是,如果我有第二个索引属性怎么办?
我知道这在 C# 中不可能直接实现,但在 VB.NET 中却可以。
Default Public Property Item(key As Object) As Object 'equivalent to this[...]'
Public Property Item2(key As Object) As Object 'a second indexed property!'
这些是我尝试过的一些绑定:
<Label Content="{Binding MyFoo["key"]}"/>
<Label Content="{Binding MyFoo.Item["key"]}"/>
<Label Content="{Binding MyFoo.Item2["key"]}"/>
第一个绑定仍然有效,但其他两个不会。
有没有直接的解决方案,还是我需要解决方法?