views:

425

answers:

2

I have a cache that retrieves collections based on a string (collection name) passed to the cache (ie... GlobalCache.Instance["States"])

I added a resource as following: < EnumCache:GlobalCache x:Key="GlobalCache" />

then the control....

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

Any ideas on how I can go about getting this to work through XAML without having to set the ItemsSource via codebehind?

It works fine through code behind but I want to simplify coding more...

+1  A: 

One solution to this that I've found is to use yet another converter and pass the parameter to the indexer as a ConveterParameter as follows:

.... 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];
 } 
}

NOTE: The other issue that I found is that ItemsSource is not exposed through XAML so there is no access to it yet without writting extenders or subclassing.

JLewis
A: 

This should work :

ItemsSource="{Binding Source={StaticResource GlobalCache}, Path=Instance[States]}"
Thomas Levesque