From 4287a449e59458fd5f98a83758232f8019f43245 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sun, 8 Nov 2026 22:36:58 -0600 Subject: [PATCH 1/3] Replace toolkit commands with small RelayCommand The menu and the three reset buttons only need a command that runs a method, so they get a small class instead of CommunityToolkit.Mvvm's generated commands. The command names stay the same, so the XAML bindings don't change. --- DesktopClock/MainWindow.xaml.cs | 22 +++++++++++++++------- DesktopClock/SettingsWindow.xaml.cs | 12 ++++++++---- DesktopClock/Utilities/RelayCommand.cs | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 DesktopClock/Utilities/RelayCommand.cs diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 7c72ba8..46bcff7 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -10,7 +10,6 @@ using System.Windows.Controls; using System.Windows.Input; using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; using DesktopClock.Properties; using DesktopClock.Utilities; using H.NotifyIcon; @@ -45,8 +44,23 @@ public partial class MainWindow : Window [ObservableProperty] private string _currentTimeOrCountdownString; + // The menu shared by the clock and the tray icon binds to these. + public ICommand CopyToClipboardCommand { get; } + public ICommand HideForNowCommand { get; } + public ICommand OpenSettingsWindowCommand { get; } + public ICommand OpenReleasesPageCommand { get; } + public ICommand OpenIssueTrackerCommand { get; } + public ICommand ExitCommand { get; } + public MainWindow() { + CopyToClipboardCommand = new RelayCommand(CopyToClipboard); + HideForNowCommand = new RelayCommand(HideForNow); + OpenSettingsWindowCommand = new RelayCommand(OpenSettingsWindow); + OpenReleasesPageCommand = new RelayCommand(OpenReleasesPage); + OpenIssueTrackerCommand = new RelayCommand(OpenIssueTracker); + ExitCommand = new RelayCommand(Exit); + InitializeComponent(); DataContext = this; @@ -149,7 +163,6 @@ private void ThemeManager_ThemeChanged(object sender, EventArgs e) /// /// Copies the current time string to the clipboard. /// - [RelayCommand] public void CopyToClipboard() { try @@ -165,7 +178,6 @@ public void CopyToClipboard() /// /// Minimizes the window. /// - [RelayCommand] public void HideForNow() { this.HideFromScreen(); @@ -200,19 +212,16 @@ public void ShowClockAndSettings() /// /// Opens a new settings window or activates the existing one. /// - [RelayCommand] public void OpenSettingsWindow() { App.ShowSingletonWindow(); } - [RelayCommand] public void OpenReleasesPage() { OpenUrl("https://github.com/danielchalmers/DesktopClock/releases"); } - [RelayCommand] public void OpenIssueTracker() { OpenUrl("https://github.com/danielchalmers/DesktopClock/issues"); @@ -221,7 +230,6 @@ public void OpenIssueTracker() /// /// Closes the app. /// - [RelayCommand] public void Exit() { Application.Current.Shutdown(); diff --git a/DesktopClock/SettingsWindow.xaml.cs b/DesktopClock/SettingsWindow.xaml.cs index 6b33d81..f976367 100644 --- a/DesktopClock/SettingsWindow.xaml.cs +++ b/DesktopClock/SettingsWindow.xaml.cs @@ -9,11 +9,11 @@ using System.Windows; using System.Windows.Automation; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Navigation; using System.Windows.Threading; using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; using DesktopClock.Properties; using Microsoft.Win32; @@ -357,9 +357,16 @@ public partial class SettingsWindowViewModel : ObservableObject /// public string AppVersion { get; } + public ICommand ResetWavFilePathCommand { get; } + public ICommand ResetWavFileIntervalCommand { get; } + public ICommand ResetBackgroundImagePathCommand { get; } + public SettingsWindowViewModel(Settings settings) { Settings = settings; + ResetWavFilePathCommand = new RelayCommand(ResetWavFilePath); + ResetWavFileIntervalCommand = new RelayCommand(ResetWavFileInterval); + ResetBackgroundImagePathCommand = new RelayCommand(ResetBackgroundImagePath); AppVersion = FileVersionInfo.GetVersionInfo(App.MainFileInfo.FullName).FileVersion; FontStyles = [ @@ -457,7 +464,6 @@ public IList FontFamilies /// /// Clears the chime sound file path. /// - [RelayCommand] public void ResetWavFilePath() { Settings.WavFilePath = string.Empty; @@ -466,7 +472,6 @@ public void ResetWavFilePath() /// /// Resets the chime interval to the default value. /// - [RelayCommand] public void ResetWavFileInterval() { Settings.WavFileInterval = default; @@ -475,7 +480,6 @@ public void ResetWavFileInterval() /// /// Clears the background image path. /// - [RelayCommand] public void ResetBackgroundImagePath() { Settings.BackgroundImagePath = string.Empty; diff --git a/DesktopClock/Utilities/RelayCommand.cs b/DesktopClock/Utilities/RelayCommand.cs new file mode 100644 index 0000000..929ad45 --- /dev/null +++ b/DesktopClock/Utilities/RelayCommand.cs @@ -0,0 +1,17 @@ +using System; +using System.Windows.Input; + +namespace DesktopClock; + +/// +/// A command that runs an action, for binding menu items and buttons to methods. +/// +public sealed class RelayCommand(Action execute) : ICommand +{ + // The commands can always run, so there's never a change to report. + public event EventHandler CanExecuteChanged { add { } remove { } } + + public bool CanExecute(object parameter) => true; + + public void Execute(object parameter) => execute(); +} From bee2b25dcfa53fd246214793ca35170672690609 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sun, 8 Nov 2026 22:37:52 -0600 Subject: [PATCH 2/3] Notify clock text changes through Fody instead of toolkit MainWindow now implements INotifyPropertyChanged itself and lets Fody weave the setter, like Settings. With both tools weaving the same setter, every tick raised the clock text change twice plus a change to the copy command; now it's raised once. The settings view model keeps the event, even though nothing in it changes, so WPF doesn't fall back to PropertyDescriptor change tracking for its bindings. --- DesktopClock/MainWindow.xaml.cs | 11 ++++++----- DesktopClock/SettingsWindow.xaml.cs | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 46bcff7..ac1f1d1 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -9,7 +9,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using CommunityToolkit.Mvvm.ComponentModel; using DesktopClock.Properties; using DesktopClock.Utilities; using H.NotifyIcon; @@ -21,8 +20,7 @@ namespace DesktopClock; /// /// Interaction logic for MainWindow.xaml /// -[ObservableObject] -public partial class MainWindow : Window +public partial class MainWindow : Window, INotifyPropertyChanged { private readonly SystemClockTimer _systemClockTimer; private TaskbarIcon _trayIcon; @@ -38,11 +36,14 @@ public partial class MainWindow : Window private readonly WheelNotches _wheelNotches = new(); private readonly PropertyChangedEventHandler _settingsPropertyChanged; +#pragma warning disable CS0067 // The event 'MainWindow.PropertyChanged' is never used. Handled by Fody. + public event PropertyChangedEventHandler PropertyChanged; +#pragma warning restore CS0067 + /// /// The current date and time in the selected time zone, or the formatted countdown text. /// - [ObservableProperty] - private string _currentTimeOrCountdownString; + public string CurrentTimeOrCountdownString { get; set; } // The menu shared by the clock and the tray icon binds to these. public ICommand CopyToClipboardCommand { get; } diff --git a/DesktopClock/SettingsWindow.xaml.cs b/DesktopClock/SettingsWindow.xaml.cs index f976367..81d0e44 100644 --- a/DesktopClock/SettingsWindow.xaml.cs +++ b/DesktopClock/SettingsWindow.xaml.cs @@ -13,7 +13,6 @@ using System.Windows.Media; using System.Windows.Navigation; using System.Windows.Threading; -using CommunityToolkit.Mvvm.ComponentModel; using DesktopClock.Properties; using Microsoft.Win32; @@ -342,8 +341,13 @@ public static class NavButton public static void SetIsActive(DependencyObject obj, bool value) => obj.SetValue(IsActiveProperty, value); } -public partial class SettingsWindowViewModel : ObservableObject +public sealed class SettingsWindowViewModel : INotifyPropertyChanged { + // Nothing here changes after it's created, but bindings to an object without this event fall back to PropertyDescriptor change tracking, which is slower and can keep the object alive after the window closes. +#pragma warning disable CS0067 // The event 'SettingsWindowViewModel.PropertyChanged' is never used. + public event PropertyChangedEventHandler PropertyChanged; +#pragma warning restore CS0067 + // Enumerating fonts and time zones costs ~100 ms and the results don't change within a session, so they're fetched once on a background thread that the app kicks off while idle after startup. private static readonly Lazy Fonts, IList TimeZones)>> _systemLists = new(() => Task.Run(() => ( From ab84bbcf9bbf3b9af851c444277259e8d85e5c38 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sun, 8 Nov 2026 22:39:26 -0600 Subject: [PATCH 3/3] Remove CommunityToolkit.Mvvm package Nothing uses it anymore. This drops it and the three packages only it needed from the embedded files, and removes its entry from the credits in Settings. --- DesktopClock/DesktopClock.csproj | 1 - DesktopClock/SettingsWindow.xaml | 6 ------ 2 files changed, 7 deletions(-) diff --git a/DesktopClock/DesktopClock.csproj b/DesktopClock/DesktopClock.csproj index 371a868..0849cf6 100644 --- a/DesktopClock/DesktopClock.csproj +++ b/DesktopClock/DesktopClock.csproj @@ -17,7 +17,6 @@ - diff --git a/DesktopClock/SettingsWindow.xaml b/DesktopClock/SettingsWindow.xaml index bf902f5..9da1e29 100644 --- a/DesktopClock/SettingsWindow.xaml +++ b/DesktopClock/SettingsWindow.xaml @@ -671,12 +671,6 @@ Style="{StaticResource CardGroupBox}"> - - - CommunityToolkit - -