c# - 组合框中的 WPF CultureInfo,DisplayName 作为 DisplayMemberPath 在更改 SelectedUICulture 时不起作用

标签 c# wpf xaml combobox cultureinfo

我写了一个小实用程序,用户可以在其中更改语言。我将可用语言(如 CultureInfo )放在 List<CultureInfo> 中, 将其绑定(bind)到组合框并使用 DisplayMemberPath指向 CultureInfo.DisplayName .

private List<CultureInfo> languageOptions = new List<CultureInfo>();

public List<CultureInfo> LanguageOptions
{
    get { return languageOptions; }
    set
    {
        languageOptions = value;
        OnPropertyChanged("LanguageOptions");
    }
}

在我的构造函数中;

foreach (/* my available languages */)
{
   cultures.Add(new CultureInfo(/* language  ie.e en-US, de-DE etc */));
}

我使用以下 XAML 来显示所选语言:

<ComboBox  x:Uid="ComboBox_3" 
    ItemsSource="{Binding LanguageOptions}"
    DisplayMemberPath="DisplayName" 
    SelectedItem="{Binding Source={x:Static properties:Settings.Default},
    Path=SelectedCulture}"/>

当 CurrentCulture 和 CurrentUICulture 设置为 en-US 时,这非常有效。

en-US example image

当用户选择一种新语言并重新启动实用程序时,我设置了 CurrentCultureCurrentUICulture对于 App.xaml.cs 中的应用程序,如下所示:

if ((TTSAutomate.Properties.Settings.Default.SelectedCulture)!=null)
{
    CultureInfo ci = TTSAutomate.Properties.Settings.Default.SelectedCulture;
    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;
}

这非常有效,因为该实用程序以正确的语言显示。 但是,显示所选语言的组合框现在只显示 Name CultureInfo 的,而不是 DisplayName .

sk-SK example image

任何人都可以就发生的事情提出建议吗?我试过了 NativeName相反,没有任何改进

最佳答案

我重新生成了几次附属程序集(没有做任何更改),然后绑定(bind)“突然”开始工作了:(

关于c# - 组合框中的 WPF CultureInfo,DisplayName 作为 DisplayMemberPath 在更改 SelectedUICulture 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39359815/

相关文章:

c# - 没有 ContentPartRecord 的自定义部件的自定义排序标准 HQL 查询

wpf - 模拟 XAML 代码继承的最佳方法是什么?

c# - 如果在等待异步调用后设置 UWP bool 值,则不会在 UI 中更新

visual-studio - 键盘命令摆脱自动生成的双引号

c# - 在 CellTemplate 中为 ListView 创建触发器? (一般与模板混淆)

c# - 将字符串与类属性名称匹配

c# - .NET 项目中的 ToolsVersion 规范

c# - 通用类型的集合

c# - 对象层次结构中的层次更改通知

wpf - 在 ItemsControl 中虚拟化高度为 * 的 ItemsControl