I have Modal Window : ContentControl (User Control) inside MainWindow and NotifyIcon. I change CurrentCulture with events handled on radiobuttons.
Like this:
// Initialization
public string LangSwitch { get; private set; } = "";
// Language switch method
private void OnEnglishRadioButtonChecked(object sender, RoutedEventArgs e)
{
LangSwitch = "en-US";
Close();
}
App.xaml.cs code:
public static void ToggleLanguage(object? sender, EventArgs e)
{
var window = (MainWindow) sender;
if (window == null || string.IsNullOrEmpty(window.LangSwitch)) return;
window.Closed -= ToggleLanguage;
window.Close();
var language = window.LangSwitch;
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
Settings.Default.LanguageCode = language;
Settings.Default.Save();
window = new MainWindow();
window.Show();
}
The MainWindow "refreshes", all the text get CurrentCulture and updating to it. But my Modal Window and NotifyIcon get CurrentCulture, but not updating they UI.
If I restart application, than they update.
I'm tried to refresh my ModalWindow Frame. Initializing new NotifyIcon and dispose previous. Set Frame content to default page (First page). Nothing helped. What I need to do?
GitHub link to the project: https://github.com/Real-Time-Messenger/FlyMessenger-desktopclient
NotifyIcon is in FlyMessenger/Core/Utils/NotifyIconManager
Thanks!
CodePudding user response:
Ok, I have another solution.
I restarting proccess with this code in App.xaml.cs:
var processName = Process.GetCurrentProcess().ProcessName;
Process.Start(processName ".exe");
Current.Shutdown();
This solution is not best and have a lot of minuses, but it works.