From fb5d364fb042a7d2df06ec676532b77d242a7fa6 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Mon, 21 Jul 2025 20:50:22 -0400 Subject: [PATCH 1/6] Enhance data binding and simplify activation logic - Updated `ListBox` in `ConductorView.axaml` to bind `SelectedItem` to `ActiveItem` for two-way data binding. - Removed `OnActivateAsync` method in `ConductorViewModel.cs` to simplify the activation process. - Adjusted `Loaded` event handling in `ActionMessage.cs` for improved clarity. - Added convention in `ConventionManager.cs` to bind `ItemsSource` of `ListBox` to `DataContext`. - Changed `Unloaded` event handler in `View.cs` to use `RoutedEventArgs` for proper cleanup in Avalon. --- .../features/Features.Avalonia/Views/ConductorView.axaml | 2 +- .../ViewModels/ConductorViewModel.cs | 5 ----- src/Caliburn.Micro.Platform/ActionMessage.cs | 1 - src/Caliburn.Micro.Platform/ConventionManager.cs | 1 + src/Caliburn.Micro.Platform/View.cs | 6 +++--- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/samples/features/Features.Avalonia/Views/ConductorView.axaml b/samples/features/Features.Avalonia/Views/ConductorView.axaml index 77b0bb4a..c3d05b0b 100644 --- a/samples/features/Features.Avalonia/Views/ConductorView.axaml +++ b/samples/features/Features.Avalonia/Views/ConductorView.axaml @@ -18,7 +18,7 @@ - + diff --git a/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs b/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs index 28b8db3a..72283798 100644 --- a/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs +++ b/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs @@ -13,11 +13,6 @@ public ConductorViewModel() Items.CollectionChanged += (s, e) => NotifyOfPropertyChange(() => CanCloseTab); } - protected override async Task OnActivateAsync(CancellationToken cancellationToken) - { - // Optionally perform any logic before activation here - await base.OnActivateAsync(cancellationToken); - } protected override async Task OnActivatedAsync(CancellationToken cancellationToken) { // Optionally perform any logic after activation here diff --git a/src/Caliburn.Micro.Platform/ActionMessage.cs b/src/Caliburn.Micro.Platform/ActionMessage.cs index 401b90b5..53ea927a 100644 --- a/src/Caliburn.Micro.Platform/ActionMessage.cs +++ b/src/Caliburn.Micro.Platform/ActionMessage.cs @@ -214,7 +214,6 @@ protected override void OnAttached() if (View.ExecuteOnLoad(AssociatedObject, ElementLoaded)) { #if AVALONIA - //string eventName = "AttachedToLogicalTree"; string eventName = "Loaded"; var trigger = Interaction.GetBehaviors(AssociatedObject) .OfType() diff --git a/src/Caliburn.Micro.Platform/ConventionManager.cs b/src/Caliburn.Micro.Platform/ConventionManager.cs index abfa30b4..b445145a 100644 --- a/src/Caliburn.Micro.Platform/ConventionManager.cs +++ b/src/Caliburn.Micro.Platform/ConventionManager.cs @@ -340,6 +340,7 @@ static ConventionManager() #endif #if AVALONIA AddElementConvention(UserControl.IsVisibleProperty, "DataContext", loadedEvent); + AddElementConvention(ListBox.ItemsSourceProperty, "DataContext", loadedEvent); #else AddElementConvention(UserControl.VisibilityProperty, "DataContext", loadedEvent); #endif diff --git a/src/Caliburn.Micro.Platform/View.cs b/src/Caliburn.Micro.Platform/View.cs index e1c63ad3..6e7c9c2e 100644 --- a/src/Caliburn.Micro.Platform/View.cs +++ b/src/Caliburn.Micro.Platform/View.cs @@ -234,13 +234,13 @@ public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler ha #if AVALONIA public static void ExecuteOnUnload(FrameworkElement element, EventHandler handler) { - EventHandler unloaded = null; + EventHandler unloaded = null; unloaded = (s, e) => { - element.DetachedFromLogicalTree -= unloaded; + element.Unloaded -= unloaded; handler(s, e); }; - element.DetachedFromLogicalTree += unloaded; + element.Unloaded += unloaded; } #else public static void ExecuteOnUnload(FrameworkElement element, RoutedEventHandler handler) From 3ea96be641ec3c30adead3a4448a2242ebff7163 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Mon, 21 Jul 2025 21:01:05 -0400 Subject: [PATCH 2/6] Update src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs b/src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs index 1c68308d..5f0a87ef 100644 --- a/src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs +++ b/src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs @@ -115,7 +115,7 @@ protected override async Task OnActivateAsync(CancellationToken cancellationToke protected override async Task OnActivatedAsync(CancellationToken cancellationToken) { - //here + if (deactivationDelay.HasValue) { await Task.Delay(deactivationDelay.Value, cancellationToken).ConfigureAwait(false); From 03f399b616e1be7cbdb74b646ac11a3ba905ae20 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Mon, 21 Jul 2025 22:00:31 -0400 Subject: [PATCH 3/6] code ql suggestions --- .../{ScreenExtenstionsTests.cs => 'ScreenExtensionsTests.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Caliburn.Micro.Avalonia.Tests/{ScreenExtenstionsTests.cs => 'ScreenExtensionsTests.cs} (100%) diff --git a/src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs b/src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs similarity index 100% rename from src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs rename to src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs From 4121ef030c72fdb72b56fbd8f390d8a9ba505609 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Wed, 23 Jul 2025 16:07:50 -0400 Subject: [PATCH 4/6] Refactor UI layout and data context management - Replaced `Panel` with `ContentControl` in `ConductorView.axaml` for better layout handling. - Changed root element from `Grid` to `StackPanel` in `TabView.axaml`, and updated data binding for `ItemsControl`. - Added `DataContext` binding convention for `Panel` in `ConventionManager.cs` to enhance data context management. --- .../Features.Avalonia/Views/ConductorView.axaml | 12 ++---------- .../features/Features.Avalonia/Views/TabView.axaml | 7 ++++--- src/Caliburn.Micro.Platform/ConventionManager.cs | 1 + 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/samples/features/Features.Avalonia/Views/ConductorView.axaml b/samples/features/Features.Avalonia/Views/ConductorView.axaml index c3d05b0b..67ad3ca9 100644 --- a/samples/features/Features.Avalonia/Views/ConductorView.axaml +++ b/samples/features/Features.Avalonia/Views/ConductorView.axaml @@ -31,16 +31,8 @@ - - - - - - - - - - + + diff --git a/samples/features/Features.Avalonia/Views/TabView.axaml b/samples/features/Features.Avalonia/Views/TabView.axaml index e9c77420..9554da6e 100644 --- a/samples/features/Features.Avalonia/Views/TabView.axaml +++ b/samples/features/Features.Avalonia/Views/TabView.axaml @@ -4,13 +4,14 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Features.CrossPlatform.Views.TabView"> - + + - + - + diff --git a/src/Caliburn.Micro.Platform/ConventionManager.cs b/src/Caliburn.Micro.Platform/ConventionManager.cs index b445145a..63c90eb1 100644 --- a/src/Caliburn.Micro.Platform/ConventionManager.cs +++ b/src/Caliburn.Micro.Platform/ConventionManager.cs @@ -341,6 +341,7 @@ static ConventionManager() #if AVALONIA AddElementConvention(UserControl.IsVisibleProperty, "DataContext", loadedEvent); AddElementConvention(ListBox.ItemsSourceProperty, "DataContext", loadedEvent); + AddElementConvention(Panel.DataContextProperty, "DataContext", loadedEvent); #else AddElementConvention(UserControl.VisibilityProperty, "DataContext", loadedEvent); #endif From 520751e498a98f23dbf17371214797c47ee2aed9 Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Thu, 24 Jul 2025 21:41:47 -0400 Subject: [PATCH 5/6] Update samples/features/Features.Avalonia/Bootstrapper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- samples/features/Features.Avalonia/Bootstrapper.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/features/Features.Avalonia/Bootstrapper.cs b/samples/features/Features.Avalonia/Bootstrapper.cs index 96804bf1..81e34d78 100644 --- a/samples/features/Features.Avalonia/Bootstrapper.cs +++ b/samples/features/Features.Avalonia/Bootstrapper.cs @@ -19,10 +19,13 @@ public Bootstrapper() Initialize(); - Task displayTask = DisplayRootViewFor(); - displayTask.Wait(); + InitializeAsync(); } + private async void InitializeAsync() + { + await DisplayRootViewFor(); + } protected override void Configure() { _container From c474e1c8c973913ef2c8c2ffc20a3881cdc3094c Mon Sep 17 00:00:00 2001 From: Ken Tucker Date: Thu, 24 Jul 2025 21:54:09 -0400 Subject: [PATCH 6/6] fix obsolete message --- src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs b/src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs index 5f0a87ef..593fbbe0 100644 --- a/src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs +++ b/src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs @@ -98,7 +98,7 @@ public override Task CanCloseAsync(CancellationToken cancellationToken = d return Task.FromResult(IsClosable); } - [Obsolete("Use OnActivateAsync instead.")] + [Obsolete("Use OnActivatedAsync instead.")] protected override async Task OnActivateAsync(CancellationToken cancellationToken) { if (deactivationDelay.HasValue) @@ -115,7 +115,7 @@ protected override async Task OnActivateAsync(CancellationToken cancellationToke protected override async Task OnActivatedAsync(CancellationToken cancellationToken) { - + if (deactivationDelay.HasValue) { await Task.Delay(deactivationDelay.Value, cancellationToken).ConfigureAwait(false);