Provides platform independent navigation at the MVVM level and a Source Generator that automatically binds view and view models and registers this in your DI container β Last 10 features: - feat: Updated packages. 2024-03-04 - feat: Moved View resolving to Navigator. 2024-03-04 - feat: Changed default DI scopes. 2024-03-04 - feat: Enable Trimming warnings. 2024-03-04 - feat: Replaced Resolver with ServiceProvider extension. 2023-12-03 - feat: Released 1.3.0. 2023-12-01 - feat(apps): Updated Uno app. 2023-11-30 - feat: Updated to net8.0. 2023-11-08 - feat: Added BeforeInitializeComponent/AfterInitializeComponent partial methods when generating constructors. Fixed ViewModel init order. 2023-09-14 - feat: Now you can implement IActivatable for window/control and it will work. 2023-09-14 π Last 10 bug fixes: - fix: Disabled HostBuilderExtensions generation if detected framework is none. 2024-03-05 - fix: Added TryDetectFramework instead DetectFramework. 2024-03-04 - fix: Renamed mvvm:Properties to mvvm:Navigation. 2024-03-04 - fix: Fixed some warnings. 2023-12-18 - fix: Fixed problems with Uno.WinUI. 2023-12-04 - fix: Added GenerateLibraryLayout. 2023-12-04 - fix: Try to use latest DependencyPropertyGenerator. 2023-12-04 - fix: Fixed broken DependencyPropertyGenerator version. 2023-12-04 - fix: Fixed problems with Avalonia. 2023-12-04 - fix: Properties now is static class. 2023-12-04
$ dotnet add package Mvvm.Navigation.MauiProvides platform independent navigation at the MVVM level and a Source Generator that automatically binds view and view models and registers this in your DI container.
.AddMvvmNavigation() call to your Host builder or IServiceCollection:public sealed partial class App
{
public App()
{
AppHost = Host
.CreateDefaultBuilder()
.AddMvvmNavigation()
.Build();
}
}
using Mvvm.Navigation;
[ViewFor<MainViewModel>]
public partial class MainPage : UserControl;
or assembly level attribute(nameof behavior is ignored and the full namespace is taken):
[assembly:MapViews(
viewsNamespace: nameof(MyNamespace.Views),
viewModelsNamespace: nameof(MyNamespace.ViewModels))]
or in .csproj:
<ItemGroup Label="Navigation">
<AssemblyAttribute Include="Mvvm.Navigation.MapViews">
<_Parameter1>nameof(MyNamespace.Views)</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
<_Parameter2>nameof(MyNamespace.ViewModels)</_Parameter2>
<_Parameter2_IsLiteral>true</_Parameter2_IsLiteral>
<ViewLifetime>Mvvm.Navigation.ServiceLifetime.Transient</ViewLifetime>
<ViewLifetime_IsLiteral>true</ViewLifetime_IsLiteral>
<ViewModelLifetime>Mvvm.Navigation.ServiceLifetime.Scoped</ViewModelLifetime>
<ViewModelLifetime_IsLiteral>true</ViewModelLifetime_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
Default lifetime is ServiceLifetime.Transient for View and ServiceLifetime.Scoped for ViewModel.
3. Add Navigator to your ViewModel:
public Navigator<ObservableObject> Navigator { get; }
<Grid>
<Button
Command="{Binding Navigator.NavigateByTypeCommand}"
CommandParameter="{x:Type viewModels:BlueViewModel}"
/>
<ContentControl Content="{Binding Navigator.CurrentView}"/>
</Grid>
Tip: you can use CommandParameter="{mvvm:Type Type=viewModels:BlueViewModel}" for WinUI/UWP/Uno platforms.
The library was written as a replacement for ReactiveUI in a real project,
and inherits some concepts from it, excluding reactivity.
If you have the same task, then the changes are as follows:
mvvm:Navigation.ViewModel and mvvm:Navigation.Navigator(includes ServiceProvider) attached dependency properties.<ContentControl Content="{Binding Navigator.CurrentView}"/>Priority place for bugs: https://github.com/HavenDV/Mvvm.Navigation/issues
Priority place for ideas and general questions: https://github.com/HavenDV/Mvvm.Navigation/discussions
I also have a Discord support channel:
https://discord.gg/g8u2t9dKgE