Mindfire.Xamarin
1.3.5
See the version list below for details.
dotnet add package Mindfire.Xamarin --version 1.3.5
NuGet\Install-Package Mindfire.Xamarin -Version 1.3.5
<PackageReference Include="Mindfire.Xamarin" Version="1.3.5" />
paket add Mindfire.Xamarin --version 1.3.5
#r "nuget: Mindfire.Xamarin, 1.3.5"
// Install Mindfire.Xamarin as a Cake Addin #addin nuget:?package=Mindfire.Xamarin&version=1.3.5 // Install Mindfire.Xamarin as a Cake Tool #tool nuget:?package=Mindfire.Xamarin&version=1.3.5
Mindfire.Xamarin
This package is used to provide a better separation between a view and view model in Xamarin. Using this pattern will prevent your view from containing any knowledge about what view model is bound to it, and prevent the view model from knowing which view is presented. It provides a programmatic way of navigating both with routes and with the traditional NavigationPage
style of navigation.
Usage
There are two different scenarios in which this library can be used. Navigation while using the new Shell
, and navigation using the traditional NavigationPage
navigation style.
The data-binding is handled via convention similar to Caliburn's convention. For a given page, the view model must be either in the same namespace or adjacent to the namespace where Page
or View
has been switched for ViewModel
. For example, if a view's namespace is MyApp.Pages.Items.ItemsPage
, then the view model must be found in one of: MyApp.Pages.Items.ItemsPageModel
, MyApp.Pages.Items.ItemsViewModel
, MyApp.ViewModels.Items.ItemsPageModel
, MyApp.ViewModels.Items.ItemViewModel
.
Shell Navigation
To use Shell
, simply create a Shell
as your main page. You can setup the shell to behave exactly as you wish -- Mindfire.Xamarin does not interfere or require a specific setup here. In the App.xaml.cs file, wire up your dependency container as you normally would. Add to it a registration for both IBinder and IRouteNavigator. You may provide your own implementations of these interfaces, or use the provided types. The IBinder implementation is SimpleBinder and it requires either an implementation of IServiceProvider, or two funcs for retrieving services from the dependency container. IRouteNavigator is fulfilled by ShellNavigator.
services.AddSingleton<IBinder>(provider => new SimpleBinder(type => provider.GetService(type), type => provider.GetServices(type)));
services.AddSingleton<IRouteNavigator>(provider =>
{
var binder = provider.GetService<IBinder>();
return new ShellNavigator(MainPage as Shell, binder);
}
// You may also provide an registration for INavigator in case you have a need to abstract the routing portion.
services.AddSingleton<INavigator>(provider => provider.GetService<IRouteNavigator>());
Once registered, simply make sure that an instance of INavigator or IRouteNavigator is created when your app starts. This is needed to allow the system to wire up the pages.
You may register routes both inside the Shell, as well as programmatically using the Routing class. You may then request the IRouteNavigator or INavigator interfaces as injection parameters to your ViewModels and use them to navigate.
Traditional Navigation
If you are not using Shell and would like to use the more traditional form of navigation, you need to register both the IBinder and INavigator interfaces. You may use your own, or use the provided implementations. As above, SimpleBinder works for the IBinder interface, and ClassicNavigator works for the INavigator interface.
services.AddSingleton<IBinder>(provider => new SimpleBinder(provider));
services.AddSingleton<INavigator>(provider => new ClassicNavigator(MainPage as NavigationPage, provider.GetService<IBinder>()));
As with the shell navigation, you must ensure that an instance of INavigator is created upon startup of your application to allow the system to wire up the pages. You may then request an INavigator instance inside your view models and navigate as you normally would.
INavigator API
NavigateTo<T>()
- Pushes the desired page onto the stack. Creation of the page is handled automatically, as is binding to the appropriate view model.
NavigateTo<TPage, TData>(TData data)
- Is identical to the above method, however this allows you to pass data to the view model of the next page. The view model must have a property of type TData, and it will automatically be assigned the passed in value
data
.
- Is identical to the above method, however this allows you to pass data to the view model of the next page. The view model must have a property of type TData, and it will automatically be assigned the passed in value
NavigateToModal<T>()
- Pushes the desired page onto the modal stack and shows the page as a modal dialog.
NavigateToModal<TPage, TData>(TData data)
- Is identical to the above method, except allowing you to pass data to the view model of the modal dialog. The view model must have a property of type TData that can be assigned the passed in value
data
.
- Is identical to the above method, except allowing you to pass data to the view model of the modal dialog. The view model must have a property of type TData that can be assigned the passed in value
NavigateToRoot()
- Navigates back to the Root of the navigation stack. This is the
Shell
for shell navigation scenarios, and theRootPage
forNavigationPage
scenarios.
- Navigates back to the Root of the navigation stack. This is the
GoBack()
- Pops a page off of the stack. If there are pages on the
ModalStack
, these are popped before any other pages. - For
Shell
navigation, if there are pages on theNavigationStack
, these are popped first. If there are none, this call is equivalent toShell.GoToAsync("..")
- Pops a page off of the stack. If there are pages on the
DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons)
- Displays an action sheet
DisplayAlert(string title, string message, string cancel)
,DisplayAlert(string title, string message, string cancel, string accept)
- Displays an alert
DisplayPrompt(string title, string message, string accept, string cancel, string placeholder, int maxLength, Keyboard keyboard, string initialValue)
- Displays a prompt window
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Mindfire.Xamarin.Abstractions (>= 1.1.3)
- Xamarin.Forms (>= 4.7.0.1080)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.7 | 784 | 1/6/2022 |
1.5.6 | 648 | 12/8/2021 |
1.5.4 | 745 | 2/16/2021 |
1.5.3 | 777 | 1/12/2021 |
1.5.2 | 762 | 12/17/2020 |
1.5.1 | 915 | 10/1/2020 |
1.4.1 | 861 | 8/4/2020 |
1.4.0 | 802 | 7/22/2020 |
1.3.5 | 826 | 7/14/2020 |
1.3.4 | 791 | 7/7/2020 |
1.3.0 | 801 | 7/2/2020 |
1.2.1 | 839 | 6/25/2020 |
1.2.0 | 843 | 6/24/2020 |
1.1.0 | 811 | 6/23/2020 |
1.0.0 | 817 | 6/23/2020 |
- Fixed bug where navigation data could attempt to be written in a readonly property.