Xamvvm.Maui
1.0.0
See the version list below for details.
dotnet add package Xamvvm.Maui --version 1.0.0
NuGet\Install-Package Xamvvm.Maui -Version 1.0.0
<PackageReference Include="Xamvvm.Maui" Version="1.0.0" />
paket add Xamvvm.Maui --version 1.0.0
#r "nuget: Xamvvm.Maui, 1.0.0"
// Install Xamvvm.Maui as a Cake Addin #addin nuget:?package=Xamvvm.Maui&version=1.0.0 // Install Xamvvm.Maui as a Cake Tool #tool nuget:?package=Xamvvm.Maui&version=1.0.0
Simple, fast and lightweight MVVM Framework for .Net Maui with fluent API
Xamvvm.Maui | Xamvvm.Maui.RxUI |
---|---|
Background
This is a fork of https://github.com/xamvvm/xamvvm to provide .Net MAUI support.
Newer packages maybe better suited for fresh projects but this should help any existing Xamarin Forms projects in the transition to .Net MAUI.
Features
- Very Easy to use. Just mark your pages / models with empty interfaces
IBasePage<TPageModelType>
/IBasePageModel
- PageModel first oriented Navigation
- Automatic wiring of BindingContext (PageModels)
- Pages / PageModels caching - more responsive UI experience!
- You're not limited to any concrete implementation of Pages, PageModels
- Fluent style extensions methods to write less code
- Navigation inside
ContentView
- Helper classes with ready to use
INotifyPropertyChanged
implementation eg.BasePageModel
- Pages have override methods to respond / intercept navigation (eg. NavgationPushing, NavigationCanPush, etc.)
- Strongly typed classes / methods / messaging
- Dependency free ICommand implementation prevents multiple execution when previous execution not finished yet
Getting Started
Initialize the Framework
You have to create an instance of a IBaseFactory implementation and set it as the current factory to use
var factory = new XamvvmMauiFactory(this);
XamvvmCore.SetCurrentFactory(factory);
That's all 😃
The PageFactory will scan your assemblies at start up and link Pages and PageModels together according to the IBasePage definition on your Pages. (You can also register your Pages manually if you want to. See Wiki)
PageModel first navigation
All pushing and popping is always done from the PageModel and not from Pages
var pageToPush = this.GetPageFromCache<DetailPageModel>();
await this.PushPageAsync(pageToPush);
// OR even shorter way:
this.PushPageFromCache<DetailPageModel>();
You can pass an int action too that is executed on the Pagemodel before displaying the page
await this.PushPageAsync(pageToPush, (pm) => pm.Init("blue", Colors.Blue));
// OR even shorter way:
var pageToPush = this.GetPageFromCache<DetailPageModel>();
this.PushPageFromCache<DetailPageModel>((pm) => pm.Init("blue", Colors.Blue));
Popping is as easy
await this.PopPageAsync();
All a page has to do is derive from IBasePage<PageModelType> with the PageModelType this Page should be linked to.For the above example calls the used classes would like this.
public partial class DetailPage : ContentPage, IBasePage<DetailPageModel>
{
public DetailPage()
{
InitializeComponent();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Examples.DetailPage"
Title="Detail Page">
<ContentPage.Content>
<Label Text="{Binding Text}" BackgroundColor="{Binding Color}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</ContentPage.Content>
</ContentPage>
public class DetailPageModel : BasePageModel
{
public void Init(string text, Color color)
{
Text = text;
Color = color;
}
public Color Color
{
get { return GetField<Color>(); }
set { SetField(value); }
}
public string Text
{
get { return GetField<string>(); }
set { SetField(value); }
}
}
<sub>You don't have to inherit from BasePageModel it's just an included convinience class</sub>
Please look into the Wiki for Detailed Information
Support
Limited support is provided but we welcome any PRs to correct any improvements or issues you have found
Example project
https://github.com/StyleTech-Hull/xamvvm.maui/tree/development/examples
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-android34.0 is compatible. net8.0-ios17.2 is compatible. net8.0-maccatalyst17.2 is compatible. net8.0-windows10.0.19041 is compatible. |
-
net8.0-android34.0
- Microsoft.Maui.Controls (>= 8.0.7)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.7)
-
net8.0-ios17.2
- Microsoft.Maui.Controls (>= 8.0.7)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.7)
-
net8.0-maccatalyst17.2
- Microsoft.Maui.Controls (>= 8.0.7)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.7)
-
net8.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 8.0.7)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Xamvvm.Maui:
Package | Downloads |
---|---|
Xamvvm.Maui.RxUI
Simple MVVM (Model, ViewModel, View) Framework for .Net - .NET MAUI ReactiveUI compatible |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release of Maui version of Xamvvm