public void ChangeLanguage(string cultureName) { if (IsMatch(CultureInfo.CurrentUICulture, cultureName)) { return; } if (!ViewModels.Any()) { return; } void ChangeLanguage() { CultureInfo.CurrentUICulture = new CultureInfo(cultureName); foreach (var viewModel in ViewModels) { viewModel.OnChangeLanguage(); } } MainThreadDesktop.BeginInvokeOnMainThread(ChangeLanguage); }
/// <summary> /// Everything has to be sent in on the constructor since things do not auto-refresh / update this is a limitation /// </summary> /// <param name="tooTip"></param> /// <param name="iconPath"></param> /// <param name="menu"></param> public LinuxTrayIcon(string tooTip, string iconPath, TContextMenu menu) { MainThreadDesktop.BeginInvokeOnMainThread(() => { var ctxMnu = new ContextMenu(); var f = DI.Get <INotifyIcon <TContextMenu> .IUIFrameworkHelper>(); f.ForEachMenuItems(menu, item => { ButtonMenuItem bmi = new ButtonMenuItem { Text = item.header, Command = new Command((s, e) => { MainThreadDesktop.BeginInvokeOnMainThread(() => { item.activated(); }); }) }; ctxMnu.Items.Add(bmi); }); ClientSize = new Size(200, 200); var image = new Icon(f.OpenAsset(new Uri(iconPath))); _tray = new TrayIndicator { //Image = Icon.FromResource(iconPath.Replace("resm:", "")), Image = image, Menu = ctxMnu, Title = tooTip }; _tray.Show(); _tray.Visible = true; }); }
protected override void BeginInvokeOnMainThread(Action action) => MainThreadDesktop.BeginInvokeOnMainThread(action);
public void SetLightOrDarkThemeFollowingSystem(bool enable) { var major = Environment.OSVersion.Version.Major; if (major < 10 || major == 10 && Environment.OSVersion.Version.Build < 18282) { return; } var currentUser = WindowsIdentity.GetCurrent()?.User; if (currentUser == null) { return; } try { if (enable) { if (isLightOrDarkThemeWatch == null) { var queryStr_ = @"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'"; var queryStr = string.Format( queryStr_, currentUser.Value, Themes_Personalize.Replace(@"\", @"\\"), AppsUseLightTheme); isLightOrDarkThemeWatch = new ManagementEventWatcher(queryStr); isLightOrDarkThemeWatch.EventArrived += (_, _) => { var value = IsLightOrDarkTheme; if (value.HasValue) { var theme_value = value.Value ? AppTheme.Light : AppTheme.Dark; MainThreadDesktop.BeginInvokeOnMainThread(() => { AppHelper.Current.SetThemeNotChangeValue(theme_value); }); } }; } isLightOrDarkThemeWatch.Start(); } else { if (isLightOrDarkThemeWatch == null) { return; } else { isLightOrDarkThemeWatch.Stop(); } } } catch { } }