« first day (1443 days earlier)      last day (2706 days later) » 

1:35 PM
Is there a simple way to handle localization of textblocks? I'm currently using a ValueConverter.
 
1:56 PM
public class StringResourceConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Resources.ResourceManager.GetString(value.ToString(), culture) ?? value.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
This is basically the converter I'm using at the moment. I guess I should've mentioned that I mean localization of bound values. :P
 
It allows changing language at runtime
Looks like: TextBlock Text="{l:Static p:Resources.Foo}" />
 
Does it work with binding?
 
where xmlns:l="http://gu.se/Localization" and xmlns:p="clr-namespace:YourStuff.Properties"
l:Static is not the framework static extension
it returns a bindingsexpression to a Translation that notifies when language changes
 
I'm not seeing where I'm supposed to place my property name.
<TextBlock Text="{Binding Name, Converter={StaticResource StringResourceConverter}}" />
That's what I have at the moment.
 
Is Name a key in resources?
 
2:09 PM
Name is a value on the VM, but the value is a key in the resources file.
 
oh, then you can skip all that and ~bind~ directly to the key in resources
cleaned up our code a lot
 

« first day (1443 days earlier)      last day (2706 days later) »