diff --git a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.HotReload.cs b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.HotReload.cs index 5d4879281400..4b5869772444 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.HotReload.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.HotReload.cs @@ -5,9 +5,11 @@ using Uno.Foundation.Logging; using Uno.UI.Helpers; -[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Microsoft.UI.Xaml.Controls.Frame), typeof(Microsoft.UI.Xaml.Controls.FrameElementMetadataUpdateHandler))] +[assembly: ElementMetadataUpdateHandlerAttribute(typeof(Microsoft.UI.Xaml.Controls.Frame), typeof(Microsoft.UI.Xaml.Controls.Frame.FrameElementMetadataUpdateHandler))] -namespace Microsoft.UI.Xaml.Controls +namespace Microsoft.UI.Xaml.Controls; + +partial class Frame { internal static partial class FrameElementMetadataUpdateHandler { @@ -20,36 +22,51 @@ public static void ElementUpdate(FrameworkElement element, Type[] updatedTypes) { typeof(FrameElementMetadataUpdateHandler).Log().LogWarning($"AfterElementReplaced should only be called with Frame instances"); } + return; } - foreach (var entry in frame.BackStack) + if (frame._useWinUIBehavior) { - var expectedType = entry.SourcePageType.GetReplacementType(); - if (entry.Instance is not null && - entry.Instance.GetType() != expectedType) + foreach (var type in updatedTypes) { - if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace)) - { - typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry instance {entry.Instance.GetType().Name} replaced by instance of {expectedType.Name}"); - } - var dc = entry.Instance.DataContext; - entry.Instance = Activator.CreateInstance(expectedType) as Page; - if (entry.Instance is not null) + // Note: Does not support CNOMUA + frame.RemovePageFromCache(type.FullName); + frame.RemovePageFromCache(type.AssemblyQualifiedName); + } + } + else // Uno's legacy implementation + { + foreach (var entry in frame.BackStack) + { + var expectedType = entry.SourcePageType.GetReplacementType(); + if (entry.Instance is not null && + entry.Instance.GetType() != expectedType) { - entry.Instance.Frame = frame; - entry.Instance.DataContext = dc; + if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace)) + { + typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry instance {entry.Instance.GetType().Name} replaced by instance of {expectedType.Name}"); + } + + var dc = entry.Instance.DataContext; + entry.Instance = Activator.CreateInstance(expectedType) as Page; + if (entry.Instance is not null) + { + entry.Instance.Frame = frame; + entry.Instance.DataContext = dc; + } } - } - if (entry.SourcePageType is not null && - entry.SourcePageType != expectedType) - { - if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace)) + if (entry.SourcePageType is not null && + entry.SourcePageType != expectedType) { - typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry SourcePageType changed from {entry.SourcePageType.Name} to {expectedType.Name}"); + if (typeof(FrameElementMetadataUpdateHandler).Log().IsEnabled(LogLevel.Trace)) + { + typeof(FrameElementMetadataUpdateHandler).Log().Trace($"Backstack entry SourcePageType changed from {entry.SourcePageType.Name} to {expectedType.Name}"); + } + + entry.SourcePageType = expectedType; } - entry.SourcePageType = expectedType; } } } diff --git a/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Uno.cs b/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Uno.cs index 8d8e04deed32..0e1be674b630 100644 --- a/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Uno.cs +++ b/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.Uno.cs @@ -4,5 +4,6 @@ namespace Microsoft.UI.Xaml.Navigation; partial class PageStackEntry { + // Note: LEGACY, not used by MUX (_useWinUIBehavior) internal Page Instance { get; set; } }