From 4f31973a2e55d62c413bd12bff7ac7c1115d7a1c Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 17 Sep 2024 02:05:20 +0200 Subject: [PATCH] Fix SelectedIndex Issue --- .../Views/GeneralSettingsView.axaml.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs b/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs index 2edd15327..a0cca6c93 100644 --- a/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs +++ b/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs @@ -20,16 +20,37 @@ public GeneralSettingsView() SettingsHelper.Settings.StartUp.OpenLastFile = ApplicationStartupBox.SelectedIndex == 1; await SettingsHelper.SaveSettingsAsync(); }; + ApplicationStartupBox.DropDownOpened += delegate + { + if (ApplicationStartupBox.SelectedIndex == -1) + { + ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 0 : 1; + } + }; MouseWheelBox.SelectionChanged += async delegate { SettingsHelper.Settings.Zoom.CtrlZoom = MouseWheelBox.SelectedIndex == 0; await SettingsHelper.SaveSettingsAsync(); }; + MouseWheelBox.DropDownOpened += delegate + { + if (MouseWheelBox.SelectedIndex == -1) + { + MouseWheelBox.SelectedIndex = SettingsHelper.Settings.Zoom.CtrlZoom ? 0 : 1; + } + }; ScrollDirectionBox.SelectionChanged += async delegate { SettingsHelper.Settings.Zoom.HorizontalReverseScroll = ScrollDirectionBox.SelectedIndex == 0; await SettingsHelper.SaveSettingsAsync(); }; + ScrollDirectionBox.DropDownOpened += delegate + { + if (ScrollDirectionBox.SelectedIndex == -1) + { + ScrollDirectionBox.SelectedIndex = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? 0 : 1; + } + }; MouseWheelBox.SelectedIndex = SettingsHelper.Settings.Zoom.CtrlZoom ? 0 : 1; ScrollDirectionBox.SelectedIndex = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? 0 : 1; ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 1 : 0; @@ -69,6 +90,11 @@ public GeneralSettingsView() { return; } + + if (language == SettingsHelper.Settings.UIProperties.UserLanguage) + { + return; + } SettingsHelper.Settings.UIProperties.UserLanguage = language; await TranslationHelper.LoadLanguage(language).ConfigureAwait(false); @@ -85,12 +111,30 @@ await Dispatcher.UIThread.InvokeAsync(() => { return; } - window.Close(); + window.Close(); }); await FunctionsHelper.SettingsWindow(); await SettingsHelper.SaveSettingsAsync(); }; + LanguageBox.DropDownOpened += delegate + { + if (LanguageBox.SelectedIndex != -1) + { + return; + } + + // Find the ComboBoxItem whose Tag matches UserLanguage + for (var i = 0; i < LanguageBox.Items.Count; i++) + { + if (LanguageBox.Items[i] is ComboBoxItem { Tag: string tag } && + tag == SettingsHelper.Settings.UIProperties.UserLanguage) + { + LanguageBox.SelectedIndex = i; + break; + } + } + }; }; } } \ No newline at end of file