动态语言选择

时间:2018-03-14 12:56:53

标签: c# uwp

我想创建一个动态语言" ListView"用户可以选择语言,然后语言将改变并保留/保存。

现在我有了这段代码:

private ObservableCollection<string> _items = new ObservableCollection<string>();

public ObservableCollection<string> Items
{
    get { return this._items; }
}

//在ListView中添加语言(Items)

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    Items.Add("English");
    Items.Add("German");
    Items.Add("French");
    Items.Add("Mandarin");
    Items.Add("Spanish");
}

// ListView选择项目

private void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
    switch (e.ClickedItem.ToString())
    {
        case "English":
            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
    break;

        case "German":
            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
    break;

        case "French":
            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "fr-FR";
    break;

        case "Mandarin":
            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "zh-Hans";
    break;

        case "Spanish":
            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "sp-SP";
    break;

        default:
            break;
    }
}

//在这个按钮中会有很多if else语句...

private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{

    //ApplicationLanguages.PrimaryLanguageOverride = "fr"; 
    this.Frame.Navigate(typeof(Shell));
}

// XAML看起来像这样

<ListView HorizontalAlignment="Center" IsItemClickEnabled="True" ItemClick="ListView_ItemClick" ItemsSource="{x:Bind Items}" Height="500" Width="200" Margin="500,200,500,200" VerticalAlignment="Center"/>

添加和选择作品,但保存没有,我的意思是我没有编程直到结束。是否有解决方案来获得像#34; Strings / de-De / resources.rew&#34;等语言资源。并将其填入列表并选择以动态方式保存?

0 个答案:

没有答案