【问题标题】:How can I localize DisplayMemberBinding in GridViewColumn to a resx file?如何将 GridViewColumn 中的 DisplayMemberBinding 本地化为 resx 文件?
【发布时间】:2017-09-01 08:54:34
【问题描述】:

我在我的应用中使用带有 resx 文件的 GUI 文本本地化:

例如,我这样写来将 GUI 文本提取到 TextBlock 中:

<TextBlock Text="{x:Static GuiText.LoginView.LoginText}" FontSize="24"\>

但是如何将本地化文本提取到 GridViewColumn 中?

如何本地化以下内容?

<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}" />

我可以本地化的 Header 至少是这样的:

<GridViewColumn Header="{x:Static GuiText.LoginView.HeaderValueText}" DisplayMemberBinding="{Binding Path=Value}" />

但是如何本地化 DisplayMemberBinding 的翻译?

【问题讨论】:

  • 你的意思是,你有特定于文化的价值观?那些是什么类型的?如果字符串和值是某个 resx 的键:您可以使用 ValueConverter,也许。但我还是有点不清楚。
  • 是的,我希望该值成为 resx 文件的键。 resx 文件有两个字符串列。第一列是我要查找值的位置,然后从第二列中我想获取一个字符串来替换该值。
  • 但这不能只用 XAML 处理吗?我必须写一个转换器吗?
  • 您到底想本地化什么? “值”是指属性的名称,它们没有本地化...

标签: c# wpf visual-studio xaml


【解决方案1】:

但是如何本地化DisplayMemberBinding 的翻译呢?

DisplayMemberBinding 的绑定路径指的是属性名称,并且这些名称未本地化。

你绑定的属性应该返回一个已经翻译的值,例如:

<GridViewColumn Header="{x:Static GuiText.LoginView.HeaderValueText}" DisplayMemberBinding="{Binding Path=TranslatedValue}" />

public string TranslatedValue
{
    get
    {
        return Resource1.String1;
    }
}

【讨论】:

    猜你喜欢
    • 2012-10-19
    • 1970-01-01
    • 2012-06-06
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多