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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MvvmEssentials.Navigation.WPF" Version="1.0.5.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MvvmEssentials.Navigation.WPF" Version="1.0.5.3" />
                    
Directory.Packages.props
<PackageReference Include="MvvmEssentials.Navigation.WPF" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MvvmEssentials.Navigation.WPF --version 1.0.5.3
                    
#r "nuget: MvvmEssentials.Navigation.WPF, 1.0.5.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MvvmEssentials.Navigation.WPF@1.0.5.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MvvmEssentials.Navigation.WPF&version=1.0.5.3
                    
Install as a Cake Addin
#tool nuget:?package=MvvmEssentials.Navigation.WPF&version=1.0.5.3
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.5.3 176 12/19/2024
1.0.5.2 147 12/18/2024
1.0.5.1 143 12/16/2024
1.0.5 144 12/16/2024
1.0.4.1 123 12/16/2024
1.0.4 127 12/16/2024
1.0.3 161 12/12/2024
1.0.2 132 12/10/2024
1.0.0 168 11/22/2024