![]() |
VOOZH | about |
dotnet add package Chinook.BackButtonManager.Uno --version 1.1.4
NuGet\Install-Package Chinook.BackButtonManager.Uno -Version 1.1.4
<PackageReference Include="Chinook.BackButtonManager.Uno" Version="1.1.4" />
<PackageVersion Include="Chinook.BackButtonManager.Uno" Version="1.1.4" />Directory.Packages.props
<PackageReference Include="Chinook.BackButtonManager.Uno" />Project file
paket add Chinook.BackButtonManager.Uno --version 1.1.4
#r "nuget: Chinook.BackButtonManager.Uno, 1.1.4"
#:package Chinook.BackButtonManager.Uno@1.1.4
#addin nuget:?package=Chinook.BackButtonManager.Uno&version=1.1.4Install as a Cake Addin
#tool nuget:?package=Chinook.BackButtonManager.Uno&version=1.1.4Install as a Cake Tool
The Chinook.BackButtonManager packages provide recipes to ease the handling of back buttons in .Net applications. It was designed for MVVM applications, but should work with other patterns too.
The Chinook namespace has other recipes for .Net MVVM applications.
BackButtonManager is especially well-integrated with Uno. Here is how to use it in a project which includes the Uno platform:
Add a package reference to Chinook.BackButtonManager.Uno (for UWP or Xamarin apps) or Chinook.BackButtonManager.Uno.WinUI (for WinUI or MAUI apps).
Create a single instance of a BackButtonManager which you will use throughout your project.
var manager = new BackButtonManager();
In your app's Startup, add the source that the manager uses to detect back button presses:
// This must be executed on the dispatcher
var source = new SystemNavigationBackButtonSource();
manager.AddSource(source);
❗ Note that
SystemNavigationManagerno longer works on Windows applications that are not UWP. On WinUI, you can no longer have a global back button in the title bar of the application.
Add handlers for each action you want to take when the back button is pressed:
manager.AddHandler(new BackButtonHandler(
name: "TODO handler name",
canHandle: () => CanYourMethodBeCalled(),
handle: async ct => await YourMethod(ct)
));
If your project does not use Uno, you can certainly use BackButtonManager! Here's how:
Add a package reference to Chinook.BackButtonManager.
Create a single instance of a BackButtonManager which you will use throughout your project.
var manager = new BackButtonManager();
You will need to create a source which implements the IBackButtonSource interface. In your app's Startup, add this source so that BackButtonManager can use it to detect back button presses.
var source = new MyBackButtonSource();
manager.AddSource(source);
Add handlers for each action you want to take when the back button is pressed:
manager.AddHandler(new BackButtonHandler(
name: "TODO handler name",
canHandle: () => CanYourMethodBeCalled(),
handle: async ct => await YourMethod(ct)
));
Using IBackButtonSource, you can implement a back button source. You can see that as an abstraction of a button. You could create sources for things like the following.
Once you have a back button source, simply add it to a IBackButtonManager using AddSource.
SystemNavigationManagerThis can be useful for UWP or Uno.UI applications. The source is based on the SystemNavigationManager.BackRequested event.
// This must be executed on the dispatcher
var source = new SystemNavigationBackButtonSource();
The interface IBackButtonSource is very simple. You can implement your own sources easily.
Using IBackButtonHandler, you can create the objects that react to back requests. Handlers can be added to (or removed from) a IBackButtonManager at any point.
That's one of the main use-case of this recipe. You likely want to create a default action to perform when a back is requested.
Here is some code showing how to setup a IBackButtonManager with a default handler in a context using Microsoft.Extensions.DependencyInjection and Chinook.Navigation.
public static IServiceCollection AddDefaultBackHandler(this IServiceCollection services)
{
return services
.AddSingleton<IBackButtonManager>(s =>
{
var manager = new BackButtonManager();
var sectionsNavigator = s.GetRequiredService<ISectionsNavigator>();
manager.AddHandler(new BackButtonHandler(
name: "DefaultSectionsNavigatorHandler",
canHandle: () => sectionsNavigator.CanNavigateBackOrCloseModal(),
handle: async ct => await sectionsNavigator.NavigateBackOrCloseModal(ct)));
return manager;
});
}
This can be useful when your page has advances states or secondary views. Imagine having a drawer or side menu. When that secondary view is active, it is likely that you want your back button to dismiss that secondary view rather than navigating to the previous page.
public MainPageViewModel(IBackButtonManager manager)
{
var customHandler = new BackButtonHandler("CustomBackHandler",
// The handler will only be invoked when the side panel is open.
canHandle: () => IsSidePanelOpen,
// Close the side panel when a back is requested.
handle: async ct => IsSidePanelOpen = false
);
var subscription = manager.RegisterHandler(customHandler);
// Automatically remove the handler when this page gets disposed.
this.AddDisposable(subscription);
}
public bool IsSidePanelOpen
{
get => this.Get<bool>(initialValue: false);
set => this.Set(value);
}
💡 This sample shows a ViewModel written using Chinook.DynamicMvvm.
It is possible to specify a priority when calling IBackButtonManager.AddHandler. The highest priority handlers will be evaluated first.
Please consult for more information about migration.
This project is licensed under the Apache 2.0 license - see the file for details.
Please read for details on the process for contributing to this project.
Be mindful of our .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. monoandroid11.0 monoandroid11.0 is compatible. monoandroid12.0 monoandroid12.0 is compatible. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Universal Windows Platform | uap10.0.19041 uap10.0.19041 is compatible. |
| Xamarin.iOS | xamarinios xamarinios was computed. xamarinios10 xamarinios10 is compatible. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.5-feature.Uno5Update.2 | 325 | 11/2/2023 |
| 1.1.4 | 824 | 10/17/2023 |
| 1.1.3 | 21,528 | 11/1/2022 |
| 1.1.2 | 1,339 | 10/12/2022 |
| 1.1.1 | 1,085 | 9/21/2022 |
| 1.1.0 | 321 | 9/16/2022 |
| 1.0.0 | 1,381 | 8/24/2022 |
| 0.5.3 | 673 | 8/24/2022 |
| 0.5.2 | 630 | 8/23/2022 |
| 0.5.1 | 667 | 8/23/2022 |
| 0.5.0-dev.33 | 55,377 | 5/18/2022 |
| 0.5.0-dev.31 | 332 | 5/3/2022 |
| 0.5.0-dev.29 | 4,653 | 3/31/2022 |
| 0.4.0-dev.27 | 458 | 3/15/2022 |
| 0.3.0-dev.22 | 61,683 | 3/16/2021 |
| 0.2.0-dev.17 | 1,787 | 12/17/2020 |
| 0.2.0-dev.15 | 1,160 | 10/30/2020 |
| 0.2.0-dev.13 | 12,477 | 8/13/2020 |
| 0.2.0-dev.11 | 460 | 8/13/2020 |
| 0.2.0-dev.9 | 1,332 | 6/26/2020 |