Я пытаюсь создать многоязычное приложение; до сих пор TextBlocks являются многоязычными и динамически меняются с одного языка на другой.
Сейчас я пытаюсь сделать MessageBox многоязычным, но ресурс не обновляется, а просто остается на языке по умолчанию.
TextBlock Text="{DynamicResource ResourceKey=Sentence}"
// updating with the ResourceDictionary
string messageBoxMessage=
(string)Application.Current.FindResource("Sentence");
// not updating with the ResourceDictionary
Я ожидаю, что messageBoxMessage
обновится так же, как TextBlock
.
Но значение messageBoxMessage
никогда не изменяется и остается значением по умолчанию.
Вот остаток кода. Сообщение MessageBox теперь является свойством, но оно по-прежнему не обновляется.
private void CBBEnglish_Selected(object sender, RoutedEventArgs e)
{
ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.Source = new Uri("/Resources/Resources.en-US.xaml", UriKind.Relative);
Resources.MergedDictionaries.Add(resourceDictionary);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
}
private void ButtonForMessagebox_Click(object sender, RoutedEventArgs e)
{
MessageBoxMessage = (string)Application.Current.FindResource("Sentence"); // not updating
MessageBox.Show(MessageBoxMessage);
}