It’s a little difficult for me to provide localized strings for the user interface in a small Silverlight 4 application. Basically, I put the Resources folder and put two resource files in it:
Statuses.resx
Statuses.ro.resx
I have enum Statuses:
public enum Statuses
{
None,
Working
}
and converter:
public class StatusToMessage : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!Enum.IsDefined(typeof(Status), value))
{
throw new ArgumentOutOfRangeException("value");
}
var x = Statuses.None;
return Statuses.ResourceManager.GetString(((Status)value).ToString(), Thread.CurrentThread.CurrentUICulture);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
in the view, I have a text block:
<TextBlock Grid.Column="3" Text="{Binding Status, Converter={StaticResource StatusToMessage}}" />
When the view is presented, the converter is invoked, but no matter what parameter Thread.CurrentThread.CurrentUICulture is set to, it always returns the default culture value.
After additional verification, I divided the resulting XAP file, took the provided DLL file in Reflector and checked the built-in resources. It contains only the default resource!
, :
:
:
: ResXFileCodeGenerator
: []
(.resx) . .Designer.cs :
Statuses.Designer.cs:
namespace SilverlightApplication5.Resources {
using System;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Statuses {
Statuses.ro.Designer.cs
[]
, , , silverlight.
?