From bde471afa87748490267f81ea72136f876d0f272 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 19 Nov 2022 16:03:44 +0800 Subject: [PATCH] Use binding for date time preview --- Flow.Launcher/SettingWindow.xaml | 27 ++++++++++-------- Flow.Launcher/SettingWindow.xaml.cs | 28 ------------------- .../ViewModel/SettingWindowViewModel.cs | 9 ++++++ 3 files changed, 25 insertions(+), 39 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 3eb2c21bb..e08ce7c40 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -39,6 +39,7 @@ + @@ -1820,9 +1821,17 @@ Style="{DynamicResource QueryBoxStyle}" Text="{DynamicResource hiThere}" /> - - - + + + + DropDownOpened="RefreshDateTimeList"/> + Style="{DynamicResource SideToggleSwitch}"/>  @@ -2211,14 +2218,12 @@ FontSize="14" ItemsSource="{Binding DateFormatDisplayList}" SelectedIndex="{Binding DateFormatIndex, Mode=OneWayToSource}" - DropDownOpened="RefreshDateTimeList" - SelectionChanged="PreviewClockAndDate" /> + DropDownOpened="RefreshDateTimeList"/> + Style="{DynamicResource SideToggleSwitch}"/>  diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 97493ca5c..8a80ed680 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -517,34 +517,6 @@ namespace Flow.Launcher } } - private void PreviewClockAndDate(object sender, RoutedEventArgs e) - { - ClockDisplay(); - } - - public void ClockDisplay() - { - if (settings.UseClock) - { - ClockBox.Visibility = Visibility.Visible; - ClockBox.Text = DateTime.Now.ToString(settings.TimeFormat); - } - else - { - ClockBox.Visibility = Visibility.Collapsed; - } - - if (settings.UseDate) - { - DateBox.Visibility = Visibility.Visible; - DateBox.Text = DateTime.Now.ToString(settings.DateFormat); - } - else - { - DateBox.Visibility = Visibility.Collapsed; - } - } - public void InitializePosition() { if (settings.SettingWindowTop >= 0 && settings.SettingWindowLeft >= 0) diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 8f02a7083..4a4cf9404 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -486,6 +486,7 @@ namespace Flow.Launcher.ViewModel { timeFormatIndex = value; Settings.TimeFormat = TimeFormatList[value]; + ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture); } } } @@ -500,10 +501,15 @@ namespace Flow.Launcher.ViewModel { dateFormatIndex = value; Settings.DateFormat = DateFormatList[value]; + DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture); } } } + public string ClockText { get; private set; } + + public string DateText { get; private set; } + public List TimeFormatDisplayList { get; set; } = null; public List DateFormatDisplayList { get; set; } = null; @@ -519,6 +525,9 @@ namespace Flow.Launcher.ViewModel { DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture); } + + ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture); + DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture); } public double WindowWidthSize