Silverlight: Binding to static value
- by queen3
I need TextBlock.Text to be retrieved from translation manager, something like
<TextBlock Text="{Binding TranslateManager.Translate('word')}" />
I don't want to set DataSource for all text blocks. The only way I found how to do this is to bind to "static" class and use converter:
<TextBlock Text="{Binding Value,
Source={StaticResource Translation},
Converter={StaticResource Translation},
ConverterParameter=NewProject}" />
And these helper class
public class TranslationManager : IValueConverter
{
public static string Translate(string word)
{
return translate(word);
}
// this is dummy for fake static binding
public string Value { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var name = parameter as string;
return TranslationManager.Translate(name, name);
}
}
But, is there a better - shorter - way?