Silverlight: Binding to static value
Posted
by queen3
on Stack Overflow
See other posts from Stack Overflow
or by queen3
Published on 2010-04-16T13:15:37Z
Indexed on
2010/04/16
14:23 UTC
Read the original article
Hit count: 357
Silverlight
|silverlight-3.0
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?
© Stack Overflow or respective owner