0

我有一个缓存,它根据传递给缓存的字符串(集合名称)检索集合(即... GlobalCache.Instance [“States”])

我添加了如下资源:< EnumCache:GlobalCache x:Key="GlobalCache" />

然后控制....

<dataControls:DataFormComboBoxField x:Name="cmbStates"
    ItemsSource="GlobalCache.Instance['States']"
    DisplayMemberPath="EnumerationValueDisplayed"
    Binding="{Binding fldState, Mode=TwoWay,Converter={StaticResource numConverterUsingEnumerationId},ConverterParameter='States'}" />

关于如何通过 XAML 使其工作而无需通过代码隐藏设置 ItemsSource 的任何想法?

它通过后面的代码工作正常,但我想更简化编码......

4

2 回答 2

1

我发现的一个解决方案是使用另一个转换器并将参数作为 ConveterParameter 传递给索引器,如下所示:

.... Binding="{Binding Converter={StaticResource CacheIndexConverter}, ConverterParameter=States}

...

public class CacheIndexConverter : IValueConverter
{
 public object Convert(object value, Type targetType, object parameter, CultureInfo    culture)
 {
   string index = parameter as string;
   return GlobalCache.Instance[index];
 } 
}

注意:我发现的另一个问题是 ItemsSource 没有通过 XAML 公开,因此如果没有编写扩展程序或子类化,就无法访​​问它。

于 2009-06-23T19:30:34.630 回答
0

这应该工作:

ItemsSource="{Binding Source={StaticResource GlobalCache}, Path=Instance[States]}"
于 2009-12-21T15:14:42.930 回答