diff --git a/README.md b/README.md index c94b959..ce2cf7e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ We welcome feedback, suggestions, and contributions from anyone who is intereste To use AvaloniaInside.Shell in your Avalonia project, you can install the package via NuGet using the following command in the Package Manager Console: ```bash -dotnet add package AvaloniaInside.Shell --version 1.3.2 +dotnet add package AvaloniaInside.Shell --version 1.3.2.2 ``` Alternatively, you can also install the package through Visual Studio's NuGet Package Manager. diff --git a/src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj b/src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj index ada87c5..35dcff5 100644 --- a/src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj +++ b/src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable latest - 1.3.2 + 1.3.2.2 Shell view for Avalonia Shell reduces the complexity of mobile/desktop application development by providing the fundamental features that most applications require AvaloniaInside diff --git a/src/AvaloniaInside.Shell/INavigator.cs b/src/AvaloniaInside.Shell/INavigator.cs index 18d03a5..d8f4e90 100644 --- a/src/AvaloniaInside.Shell/INavigator.cs +++ b/src/AvaloniaInside.Shell/INavigator.cs @@ -9,6 +9,8 @@ public interface INavigator { Uri CurrentUri { get; } + event EventHandler? OnNavigate; + INavigationRegistrar Registrar { get; } NavigationChain? CurrentChain { get; } diff --git a/src/AvaloniaInside.Shell/Navigator.cs b/src/AvaloniaInside.Shell/Navigator.cs index d189083..f993d24 100644 --- a/src/AvaloniaInside.Shell/Navigator.cs +++ b/src/AvaloniaInside.Shell/Navigator.cs @@ -18,6 +18,8 @@ public partial class Navigator : INavigator private bool _navigating; private ShellView? _shellView; + public event EventHandler? OnNavigate; + public ShellView ShellView => _shellView ?? throw new ArgumentNullException(nameof(ShellView)); public Uri CurrentUri => _stack.Current?.Uri ?? Registrar.RootUri; @@ -154,6 +156,20 @@ await _updateStrategy.UpdateChangesAsync( await fromPage.OnNavigateAsync(args, cancellationToken); } + // Fire the OnNavigate event for external subscribers + OnNavigate?.Invoke(this, new NaviagateEventArgs + { + Sender = sender, + From = fromPage, + To = _stack.Current?.Instance, + FromUri = origin, + ToUri = newUri, + Argument = argument, + Navigate = finalNavigateType, + WithAnimation = withAnimation, + OverrideTransition = overrideTransition + }); + _navigating = false; } diff --git a/src/AvaloniaInside.Shell/StackContentView.cs b/src/AvaloniaInside.Shell/StackContentView.cs index 98ffb74..91dd1a6 100644 --- a/src/AvaloniaInside.Shell/StackContentView.cs +++ b/src/AvaloniaInside.Shell/StackContentView.cs @@ -60,8 +60,17 @@ public async Task PushViewAsync(object view, // Bring to front if exists in collection if (Children.Contains(control)) - Children.Remove(control); - Children.Add(control); + { + var currentIndex = Children.IndexOf(control); + if (currentIndex != Children.Count - 1) + { + Children.Move(currentIndex, Children.Count - 1); + } + } + else + { + Children.Add(control); + } await OnContentUpdateAsync(control, cancellationToken); await UpdateCurrentViewAsync(current, control, navigateType, false, cancellationToken); diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 739b949..3881585 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -4,20 +4,19 @@ true - - - - - - - - - - + + + + + + + + + - - - - + + + + diff --git a/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml b/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml index 70ee737..34e2a51 100644 --- a/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml +++ b/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml @@ -8,5 +8,5 @@ Icon="/Assets/avalonia-logo.ico" Title="ShellExample" Width="450"> - + diff --git a/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml.cs b/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml.cs index f9a4814..06958c6 100644 --- a/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml.cs +++ b/src/Example/ShellExample/ShellExample/Views/MainWindow.axaml.cs @@ -1,5 +1,7 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Interactivity; +using AvaloniaInside.Shell; namespace ShellExample.Views; @@ -11,4 +13,34 @@ public MainWindow() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + + // Subscribe to navigation events to update window title + if (MainView.Navigator != null) + { + MainView.Navigator.OnNavigate += OnNavigate; + } + } + + protected override void OnUnloaded(RoutedEventArgs e) + { + // Unsubscribe from navigation events + if (MainView.Navigator != null) + { + MainView.Navigator.OnNavigate -= OnNavigate; + } + + base.OnUnloaded(e); + } + + private void OnNavigate(object? sender, NaviagateEventArgs e) + { + if (e.To is AvaloniaObject targetView) + { + var header = NavigationBar.GetHeader(targetView) as string; + Title = header ?? "Shell Example"; + } + } }