Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 1, 2025

This PR implements automatic synchronization of the window title with the navigation bar header, addressing the user request to have the window title reflect the current page's navigation bar content.

Changes Made

Core Implementation

  • MainWindow.axaml: Added x:Name="MainView" to enable code-behind access to the ShellView
  • MainWindow.axaml.cs: Added property change listener in OnLoaded() that:
    • Listens to MainView.ContentView.PropertyChanged events
    • Detects when StackContentView.CurrentViewProperty changes (navigation occurs)
    • Extracts header using NavigationBar.GetHeader(newValue) as string
    • Updates window Title property with the header value or defaults to "Shell Example"

Compatibility Fixes

  • NavigationStack.cs: Converted primary constructor to traditional constructor for .NET 8.0 compatibility
  • HostedItemsHelper.cs: Converted primary constructors to traditional constructors for .NET 8.0 compatibility

How It Works

The implementation follows the approach suggested by @OmidID in the issue comments:

MainView.ContentView.PropertyChanged += (sender, args) =>
{
    if (args.Property == StackContentView.CurrentViewProperty)
    {
        if (args.NewValue is AvaloniaObject newValue)
        {
            var header = NavigationBar.GetHeader(newValue) as string;
            Title = header ?? "Shell Example";
        }
    }
};

Example Behavior

  • Navigate to HomePage (NavigationBar.Header="Home") → Window title: "Home"
  • Navigate to SettingView (NavigationBar.Header="Settings") → Window title: "Settings"
  • Navigate to ProfileView (NavigationBar.Header="Profile") → Window title: "Profile"
  • Page with no header set → Window title: "Shell Example" (fallback)

The solution provides automatic synchronization without requiring manual title updates and includes proper null safety checks.

Fixes #97.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.31/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.31/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 1, 2025 18:04
Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>
Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>
Copilot AI changed the title [WIP] Synchronize the title of the window with the navigation bar Synchronize window title with navigation bar header Jul 1, 2025
Copilot AI requested a review from OmidID July 1, 2025 18:06
Copilot finished work on behalf of OmidID July 1, 2025 18:06
Copy link
Contributor

@OmidID OmidID left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add OnNavigate event to INavigator. and use that event in ShellExample.

ignore ShellBottomCustomNavigator

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

Add OnNavigate event to INavigator. and use that event in ShellExample.

ignore ShellBottomCustomNavigator

Implemented OnNavigate event in INavigator interface and updated ShellExample to use it instead of property change listener. Event fires after successful navigation in Navigator.NotifyAsync(). Changes in commit 305d67c.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.31/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.31/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>
Copilot finished work on behalf of OmidID July 2, 2025 18:23
Copilot AI requested a review from OmidID July 2, 2025 18:23
@OmidID OmidID marked this pull request as ready for review July 2, 2025 18:29
@OmidID OmidID self-requested a review July 2, 2025 18:31
@OmidID OmidID merged commit 8bdacfe into develop Jul 2, 2025
4 checks passed
OmidID added a commit that referenced this pull request Sep 3, 2025
* Update dependency Projektanker.Icons.Avalonia.FontAwesome to 8.4.0 (#86)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency Projektanker.Icons.Avalonia to 8.4.0 (#85)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency Projektanker.Icons.Avalonia to v9 (#95)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency Projektanker.Icons.Avalonia.FontAwesome to v9 (#96)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix issue of crash when host navigate back (#100)

* #98 fix issue of crash when host navigate back

* Update src/AvaloniaInside.Shell/StackContentView.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dependency ReactiveUI to 20.3.1 (#99)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update avalonia monorepo to 11.3.1 (#101)

* Update avalonia monorepo to 11.3.1

* Update src/Directory.Packages.props

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Directory.Packages.props

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dependency Xamarin.AndroidX.Core.SplashScreen to 1.0.1.16 (#102)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update avalonia monorepo to 11.3.2 (#103)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency ReactiveUI to 20.4.1 (#104)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Synchronize window title with navigation bar header (#105)

* Initial plan

* Implement window title synchronization with navigation bar header

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

* Clean up implementation and restore original target frameworks

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

* Implement OnNavigate event and revert primary constructor changes

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

* Restore original target frameworks

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

* Update avalonia monorepo to 11.3.4 (#108)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency Xamarin.AndroidX.Core.SplashScreen to 1.0.1.17 (#109)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency ReactiveUI to v21 (#110)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update avalonia monorepo to 11.3.5 (#111)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Release version 1.3.2.2 - Update package version in csproj and README (#112)

* Initial plan

* Update version to 1.3.2.2 in csproj and README

Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>

---------

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OmidID <956077+OmidID@users.noreply.github.com>
@OmidID OmidID deleted the copilot/fix-97 branch September 3, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synchronize the title of the window with the navigation bar

2 participants