Using embedded resources in Silverlight (4) - other cultures not being compiled
Posted
by Andrei Rinea
on Stack Overflow
See other posts from Stack Overflow
or by Andrei Rinea
Published on 2010-06-09T13:31:26Z
Indexed on
2010/06/09
19:42 UTC
Read the original article
Hit count: 482
I am having a bit of a hard time providing localized strings for the UI in a small Silverlight 4 application. Basically I've put a folder "Resources" and placed two resource files in it :
Statuses.resx
Statuses.ro.resx
I do have an enum Statuses :
public enum Statuses
{
None,
Working
}
and a convertor :
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 textblock :
<TextBlock Grid.Column="3" Text="{Binding Status, Converter={StaticResource StatusToMessage}}" />
Upon view rendering the converter is called but no matter what the Thread.CurrentThread.CurrentUICulture is set it always returns the default culture value.
Upon further inspection I took apart the XAP resulted file, taken the resulted DLL file to Reflector and inspected the embedded resources. It only contains the default resource!!
Going back to the two resource files I am now inspecting their properties :
Build action : Embedded Resource Copy to output directory : Do not copy Custom tool : ResXFileCodeGenerator Custom tool namespace : [empty]
Both resource (.resx) files have these settings. The .Designer.cs resulted files are as follows :
Statuses.Designer.cs :
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SilverlightApplication5.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[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 {
// ... yadda-yadda
Statuses.ro.Designer.cs
[empty]
I've taken both files and put them in a console application and they behave as expected in it, not like in this silverlight application.
What is wrong?
© Stack Overflow or respective owner