From 4c21b8ab80f55dceb81b08c6fcb7fbda8d6c39f9 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Tue, 25 Feb 2025 07:03:47 -0500 Subject: [PATCH 1/2] Improve binding logic and logging in ActionMessage.cs - Updated binding initialization to use object initializer syntax for better readability. - Enhanced logging for `source` enabled status, including checks for `source.Name`. - Added logging to indicate whether `source` is enabled or disabled after `CanExecute` check. - Implemented null checks for `source` and its `DataContext` to prevent null reference exceptions. --- src/Caliburn.Micro.Platform/ActionMessage.cs | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Caliburn.Micro.Platform/ActionMessage.cs b/src/Caliburn.Micro.Platform/ActionMessage.cs index 8e09cf48..e4f42750 100644 --- a/src/Caliburn.Micro.Platform/ActionMessage.cs +++ b/src/Caliburn.Micro.Platform/ActionMessage.cs @@ -315,8 +315,9 @@ void ElementLoaded(object sender, RoutedEventArgs e) Log.Info($"Binding {binding.Source}"); #elif (NET || CAL_NETCORE) && !WinUI3 && !WINDOWS_UWP - var binding = new Binding { - Path = new PropertyPath(Message.HandlerProperty), + var binding = new Binding + { + Path = new PropertyPath(Message.HandlerProperty), Source = currentElement }; #elif WINDOWS_UWP || WinUI3 @@ -536,7 +537,23 @@ public override string ToString() if (!hasBinding && context.CanExecute != null) { Log.Info($"ApplyAvailabilityEffect CanExecute {context.CanExecute()} - {context.Method.Name}"); - source.IsEnabled = context.CanExecute(); + if (!string.IsNullOrEmpty(source.Name)) + { + Log.Info($"ApplyAvailabilityEffect CanExecute {context.CanExecute()} - {context.Method.Name} - {source.Name}"); + source.IsEnabled = context.CanExecute(); + } + else + { + Log.Info("Skipping is enabled because source Name is not set"); + } + if (!source.IsEnabled) + { + Log.Info($"Disabled {source.Name}"); + } + else + { + Log.Info($"Enabled {source.Name}"); + } } #endif Log.Info($"ApplyAvailabilityEffect source enabled {source.IsEnabled}"); @@ -615,6 +632,7 @@ public override string ToString() } } #else + if (source != null && source.DataContext != null) { var target = source.DataContext; From bce4876464967858f3565b6b25d079c6471676fb Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Tue, 25 Feb 2025 07:12:02 -0500 Subject: [PATCH 2/2] update logging message --- src/Caliburn.Micro.Platform/ActionMessage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Caliburn.Micro.Platform/ActionMessage.cs b/src/Caliburn.Micro.Platform/ActionMessage.cs index e4f42750..cb4aa587 100644 --- a/src/Caliburn.Micro.Platform/ActionMessage.cs +++ b/src/Caliburn.Micro.Platform/ActionMessage.cs @@ -544,7 +544,7 @@ public override string ToString() } else { - Log.Info("Skipping is enabled because source Name is not set"); + Log.Info("Skipping IsEnabled source because source Name is not set"); } if (!source.IsEnabled) {