代码之家  ›  专栏  ›  技术社区  ›  Andrei Rînea

使用Silverlight中的嵌入资源(4)-其他区域性未编译

  •  3
  • Andrei Rînea  · 技术社区  · 14 年前

    在一个小的silverlight4应用程序中为UI提供本地化的字符串有点困难。基本上我放了一个文件夹“Resources”并在其中放置了两个资源文件:

    Statuses.resx
    Statuses.ro.resx
    

    我有一个枚举状态:

    public enum Statuses
    {
        None,
        Working
    }
    

    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();
        }
    }
    

    在视图中,我有一个文本块:

        <TextBlock Grid.Column="3" Text="{Binding Status, Converter={StaticResource StatusToMessage}}" />
    

    生成操作:嵌入资源 自定义工具:ResXFileCodeGenerator 自定义工具命名空间:[空]

    两个资源(.resx)文件都有这些设置。.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
    

    状态.ro.Designer.cs

    [空]

    怎么了?

    1 回复  |  直到 14 年前
        1
  •  6
  •   Mike Guthrie    10 年前

    结果你只需要再做一件有色彩的事。作为 MSDN article 说:

    在解决方案资源管理器中,右键单击 项目名称,然后单击“卸载” 项目关闭项目,同时

    在解决方案资源管理器中,右键单击 项目名称,然后单击“编辑”。

    Studio XML编辑器。

    中立和特定的地区 您的应用程序已创建到 < 支持的文化 应用程序支持多个 把他们的名字分开。此列表 文化不应该包括你的 例如,a< &燃气轮机;标记 是英语(“en”),支持 英国-美国(“en-US”), 法语(“fr”),法语-法国 (“fr fr”)、俄语(“ru”)和俄语 -俄罗斯(“ru-ru”)文化可能表现为:

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

    现在它工作了:D