Using Embedded Resources in Silverlight (4) - Other Cultures That Do Not Compile

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:

//------------------------------------------------------------------------------
// <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

[]

, , , silverlight.

?

+3
1

, . MSDN :

, "" .

, "".

Visual XML-Studio.

- , < SupportedCultures > . , (;) . . , < SupportedCultures > , ( "en" ) - ( "en-US" ), ( "fr" ), - ( "fr-FR" ), ( "ru" ) - ( "ru-RU" ) :

<SupportedCultures>en-US;fr;fr-FR;ru;ru-RU;</SupportedCultures>

, f! @# , .

: D

+6

Source: https://habr.com/ru/post/1749207/


All Articles