不能在XAML中访问索引器,这是接口的显式实现。
您可以为每个接口编写一个值转换器,在绑定和设置中使用适当的转换器。
ConverterParameter
至所需键:
public class Interface1Indexer : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value as ITestCaseInterface1)[parameter as string];
}
public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException("one way converter");
}
}
<TextBlock Text="{Binding Converter={StaticResource interface1Indexer}, ConverterParameter='abc'" />
当然,绑定属性必须
public
而显式实现具有特殊的状态。这个问题可能有帮助:
Why Explicit Implementation of a Interface can not be public?