c# - 为什么我不能本地化我的 WPF 程序?我在 PresentationFramework.dll 中得到 "Exception thrown: ' System.Windows.Markup.XamlParseException'

标签 c# wpf

<分区>

我有一个 WPF 程序,当我本地化它时,它失败了。我在 Window 元素中创建了这个与文件位置相对应的 XML 命名空间:

xmlns:properties="clr-namespace:ResxEditor.Properties"

这就是我本地化每个元素的方式:

<Button Content="{x:Static properties:Resources.FilePickerButton_AddFile}" />

设计器工作得非常好,当我选择 Resources. 时,自动完成会拉出可用的项目,但是当我构建我的应用程序时,它崩溃并显示以下错误消息:

Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

Additional information: 'Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.' Line number '5' and line position '9'.

行号和位置对应于我上面给出的命名空间中的第一个x。我尝试在网络上搜索此消息,但似乎找不到任何内容。

最佳答案

在网上搜索了大约一个小时后,我偶然碰巧尝试将 Resources.resx 文件的访问修饰符从 internal 更改为 public。为此,请在 Visual Studio 编辑器中打开您的 .resx 文件,并将标有“访问修饰符”的下拉菜单更改为“公共(public)”,这应该是除“内部”之外的唯一其他选项。

enter image description here

这将更改 .designer 文件中的所有项目以使用 public 访问修饰符。这些项目的示例如下所示:

/// <summary>
///   Looks up a localized string similar to Add Files.
/// </summary>
public static string FilePickerButton_AddFile {
    get {
        return ResourceManager.GetString("FilePickerButton_AddFile", resourceCulture);
    }
}

关于c# - 为什么我不能本地化我的 WPF 程序?我在 PresentationFramework.dll 中得到 "Exception thrown: ' System.Windows.Markup.XamlParseException',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32195314/

相关文章:

c# - 复制 .csproj 的最佳方法是什么(用于创建具有不同命名 exe 的相同应用程序)?

c# - 每秒刷新一次表格

c# - aspnet-api-版本控制 : Why api returns 200 (ok) if wrong Api version is provided in the call to api

c# - 问题单元测试 EF 和 ASP.NET Identity - NotSupportedException : Model Compatibility

c# - 无法将枚举绑定(bind)到组合框 wpf mvvm

c# - WPF Datagrid 多个同步卡住,由 GridSplitter 分隔的可折叠 Pane

c# - 任务被取消

c# - 我的 Get 方法将某些字段返回为 null,而 GetById 方法返回所有内容

c# - 在 C# 中将 WPF 属性绑定(bind)到 ApplicationSettings 的最佳方法?

.net - 绑定(bind)到 DataContext 属性的附加属性