Mvvm.Navigation.Wpf
1.5.1
dotnet add package Mvvm.Navigation.Wpf --version 1.5.1
NuGet\Install-Package Mvvm.Navigation.Wpf -Version 1.5.1
<PackageReference Include="Mvvm.Navigation.Wpf" Version="1.5.1" />
paket add Mvvm.Navigation.Wpf --version 1.5.1
#r "nuget: Mvvm.Navigation.Wpf, 1.5.1"
// Install Mvvm.Navigation.Wpf as a Cake Addin #addin nuget:?package=Mvvm.Navigation.Wpf&version=1.5.1 // Install Mvvm.Navigation.Wpf as a Cake Tool #tool nuget:?package=Mvvm.Navigation.Wpf&version=1.5.1
Mvvm.Navigation
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.
🔥Features🔥
- Uses DI to resolve your view from view model.
- Generates constructors for your views(optional).
- Generates an extension method for you with all your Views and ViewModels to register them in DI.
- Does not contain custom controls, everything happens based on the attached dependency property and does not limit the user.
- Allows forward/backward navigation like in Chrome.
- Allows you to receive activation/deactivation events - just implement IActivatableViewModel for your ViewModel.
- Allows you to generate a typed ViewModel property via an attribute, bound to your BindingContext and initialized from DI.
- Supports automatic mapping between View and ViewModel based on a global attribute.
- Allows case-by-case, attribute-based control for Views.
Usage
- Add
.AddMvvmNavigation()
call to your Host builder orIServiceCollection
:
public sealed partial class App
{
public App()
{
AppHost = Host
.CreateDefaultBuilder()
.AddMvvmNavigation()
.Build();
}
}
- Add ViewFor attribute to your views:
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; }
- Add commands to your views(or just use Navigator from ViewModel):
<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.
Base
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:
- Replace RoutingState with Navigator
- Replace IScreen with INavigable
- Replace ReactiveUserControl with UserControl
- Replace ReactiveWindow with Window
- Replace RoutedViewHost and ViewModelViewHost with ContentControl
- Use
mvvm:Navigation.ViewModel
andmvvm:Navigation.Navigator
(includes ServiceProvider) attached dependency properties. - Or just bind like this
<ContentControl Content="{Binding Navigator.CurrentView}"/>
Support
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
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. |
-
net8.0-windows7.0
- Mvvm.Navigation.Core (>= 1.5.1)
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.1 | 215 | 3/5/2024 |
1.5.0 | 129 | 3/4/2024 |
1.4.5 | 225 | 12/4/2023 |
1.4.4 | 136 | 12/4/2023 |
1.4.3 | 136 | 12/4/2023 |
1.4.1 | 127 | 12/3/2023 |
1.4.0 | 134 | 12/3/2023 |
1.3.0 | 122 | 12/1/2023 |
1.2.7 | 183 | 9/22/2023 |
1.2.6 | 131 | 9/22/2023 |
1.2.5 | 129 | 9/21/2023 |
1.2.4 | 125 | 9/16/2023 |
1.2.3 | 117 | 9/16/2023 |
1.2.2 | 149 | 9/14/2023 |
1.2.1 | 149 | 9/14/2023 |
1.2.0 | 138 | 9/14/2023 |
1.1.3 | 139 | 9/11/2023 |
1.1.2 | 137 | 9/11/2023 |
1.1.1 | 118 | 9/7/2023 |
1.1.0 | 124 | 9/5/2023 |
1.0.1 | 133 | 9/4/2023 |
1.0.0 | 127 | 9/3/2023 |
0.2.0 | 138 | 9/3/2023 |
0.1.0 | 129 | 9/2/2023 |
⭐ 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