MvvmEssentials.Navigation.WPF
1.0.5.3
dotnet add package MvvmEssentials.Navigation.WPF --version 1.0.5.3
NuGet\Install-Package MvvmEssentials.Navigation.WPF -Version 1.0.5.3
<PackageReference Include="MvvmEssentials.Navigation.WPF" Version="1.0.5.3" />
<PackageVersion Include="MvvmEssentials.Navigation.WPF" Version="1.0.5.3" />
<PackageReference Include="MvvmEssentials.Navigation.WPF" />
paket add MvvmEssentials.Navigation.WPF --version 1.0.5.3
#r "nuget: MvvmEssentials.Navigation.WPF, 1.0.5.3"
#:package MvvmEssentials.Navigation.WPF@1.0.5.3
#addin nuget:?package=MvvmEssentials.Navigation.WPF&version=1.0.5.3
#tool nuget:?package=MvvmEssentials.Navigation.WPF&version=1.0.5.3
MvvmEssentails.Navigation.WPF
This package contains the implementation of IDialogService and INavigationService whose contracts were defined in the MvvmEssentials.Core nuget package. Also contains some helper methods.
THIS PACKAGE IS DEPENDANT OF THE IServiceProvider INTERFACE.
How to use
Inject the INavigationService and IDialogService into the Host.
IHost _host =
Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c =>
{
var entryAssembly = Assembly.GetEntryAssembly() ?? throw new Exception("Entry assembly is null. Occured while cofigurating the application host.");
var assemblyPath = Path.GetDirectoryName(entryAssembly.Location);
if (string.IsNullOrEmpty(assemblyPath))
throw new Exception("Directory path of EntryAssembly is null");
c.SetBasePath(assemblyPath);
})
.ConfigureAppConfiguration(d1 =>
{
})
.ConfigureServices((context, services) =>
{
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<ApplicationHostService>();
...
})
.Build();
Set the NavigationName of the Frame in xaml as follows:
<Window
xmlns:navigation="clr-namespace:MvvmEssentials.Navigation.WPF.Navigation;assembly=MvvmEssentials.Navigation.WPF">
<Grid>
<Frame navigation:NavigationNamesAP.NavigationName="mainRegion"/>
</Grid>
</Window>
Receive the services into the view model and use them as follows. IsNavigationContentEnum and IsDialogContentEnum attributes must be set on the enums along with NavigateTo attribute on it's properties for the services to work(if you're using enums)
[IsNavigationContentEnum]
public enum NavigationContent
{
[NavigateTo(DestinationType = typeof(Page1))]
NavigationPage1,
[NavigateTo(DestinationType = typeof(Page2))]
NavigationPage2
}
[IsDialogContentEnum]
public enum DialogContent
{
[NavigateTo(DestinationType = typeof(DialogPage1))]
DialogPage1
}
public class MainWindowViewModel : ObservableObject
{
private readonly IDialogService dialogService;
private readonly INavigationService navigationService;
public MainWindowViewModel(IDialogService dialogService, INavigationService navigationService)
{
this.dialogService = dialogService;
this.navigationService = navigationService;
}
private void OpenSecondWindow()
{
dialogService.Show(typeof(SecondWindow), new Parameters());
//Open a dialog by creating a Window for it. DO NOT REGISTER THIS WINDOW AS SINGLETON, or else the service will throw an error when the application tries to
//open the dialog a second time.
DialogResult result = dialogService.ShowDialog(typeof(SecondWindow), new DialogParameters(), DialogCallback);
//using enum to open a dialog. A default dialog window will host the content so it must not be a Window. Use a Page or UserControl.
DialogResult result2 = dialogService.ShowDialog(DialogContent.DialogPage1, new DialogParameters(), DialogCallback);
//This is a simple dialog, just specify the parameters and it will return true if the button containing text specified in the button 1 was clicked.
bool result3 = dialogService.ShowSimpleDialog("Simple Dialog", "Are you sure you want to delete this item?", "Yes", "No");
}
private void NavigateToNextPage()
{
//navigating to the different page. NavigationNamesAP attached property must be assigned to the Frame and used here.
navigationService.Navigate("mainRegion", typeof(Page2), new NavigationParameters());
//Navigating using an enum. IsNavigationContentEnum and NavigateTo attributes must be assigned as shown above.
navigationService.Navigate("mainRegion", NavigationContent.NavigationPage2, new NavigationParameters());
//attempts to navigate back to the previous page
navigationService.NavigateBack("mainRegion");
//navigates to the next page after the frame has already navigated back.
navigationService.NavigateForward("mainRegion");
}
private void DialogCallback(IDialogParameters? parameters)
{
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0-windows7.0 is compatible. net6.0-windows was computed. net7.0-windows was computed. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
-
net5.0-windows7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- MvvmEssentials.Core (>= 1.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.