Ich poste jetzt Abschnitte aus dem Source code um das Problem zu verdeutlichen:
die Sprachumschaltung habe ich auch mit xaml ressourcen realisiert und ich lade die Strings über FindResource in Code behind datei.
die Spracheumschaltung:
private void ChangeLanguage(string culture)
{
// List all our resources
List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
{
dictionaryList.Add(dictionary);
}
// We want our specific culture
string requestedCulture = string.Format(@"Resources\Languages\StringResources.{0}.xaml", culture);
ResourceDictionary resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
if (resourceDictionary == null)
{
// If not found, we select our default language
requestedCulture = @"Resources\Languages\StringResources.xaml";
resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
}
// If we have the requested resource, remove it from the list and place at the end.\
// Then this language will be our string table to use.
if (resourceDictionary != null)
{
Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
}
if (CultureInfo.CurrentCulture.Name.Equals(culture))
return;
// Inform the threads of the new culture
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Languages-->
<ResourceDictionary Source="Resources\Languages\StringResources.de-DE.xaml" />
<ResourceDictionary Source="Resources\Languages\StringResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
die Buttons-Callbacks
private void step1Clicked(object sender, RoutedEventArgs e)
{
InformationTextBlock.Text = m_upDown.m_win.FindResource("uploadInfoStep2").ToString();
uploadStep1.IsEnabled = false;
uploadStep2.IsEnabled = true;
}
private void step2Clicked(object sender, RoutedEventArgs e)
{
InformationTextBlock.Text = m_upDown.m_win.FindResource("uploadInfoStep3").ToString();
uploadStep2.IsEnabled = false;
uploadStep3.IsEnabled = true;
}
....
in xaml
<TextBlock TextWrapping="Wrap" Name="InformationTextBlock" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="9"></TextBlock>
wenn Ich die Sprache ändere wird der textblock nicht gleich aktualisiert was auch logisch ist. erst wenn ich den nächsten Button klicke wird der Text in der richtige Sprache angezeigt.
wie kann so programmieren dass der Text automatisch in richtiger Sprache angezeigt wird wenn ich die Sprache ändere?
die Lokalaisierung der andere Texten in wpf xaml funktioniert einwandfrei mit DynamicResource