gpt4 book ai didi

silverlight - Silverlight中使用嵌入式资源(四)——其他文化不编译

转载 作者:行者123 更新时间:2023-12-04 02:56:47 25 4
gpt4 key购买 nike

我在为小型 Silverlight 4 应用程序中的 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();
}
}

在 View 中我有一个文本 block :

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

在 View 呈现时调用转换器,但无论 Thread.CurrentThread.CurrentUICulture 设置什么,它始终返回默认文化值。

经过进一步检查,我拆开了 XAP 结果文件,将结果 DLL 文件带到 Reflector 并检查了嵌入式资源。它只包含默认资源!!

回到我正在检查它们属性的两个资源文件:

构建操作:嵌入式资源复制到输出目录:不要复制自定义工具:ResXFileCodeGenerator自定义工具命名空间:[空]

两个资源 (.resx) 文件都有这些设置。 .Designer.cs 结果文件如下:

状态.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 应用程序不同。

怎么了?

最佳答案

事实证明,您只需要再做一件小事。作为MSDN article说:

In Solution Explorer, right-click the project name, and then click Unload Project to close the project while leaving the project icon visible.

In Solution Explorer, right-click the project name, and then click Edit.

The project file opens in the Visual Studio XML Editor.

In the project file, add the names of the region-neutral and specific cultures whose satellite assemblies your application has created to the <SupportedCultures> tag. If your application supports multiple cultures, use a semicolon (;) to separate their names. This list of cultures should not include your application's default culture. For example, a <SupportedCultures> tag for an application whose default culture is English ("en") and that supports the English - United States ("en-US"), French ("fr"), French - France ("fr-FR"), Russian ("ru"), and Russian - Russia ("ru-RU") cultures might appear as follows:

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

所以,记得 f!@#ingly 手动编辑项目文件并指定要包含在编译中的文化。

现在有效了:D

关于silverlight - Silverlight中使用嵌入式资源(四)——其他文化不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3006263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com