Navigation and Routing

From truxwiki.com
Jump to navigation Jump to search

This page is intended to document the Navigation and Routing of the WPF applilcation, or the way different Pages and Windows are opened and closed.

UI Guide Menu

  1. Entry Point
  2. Navigation and Routing
  3. Databinding

Main Files

File Summary Path
PageManager.cs This class manages the navigation tools such as : page loading, the bread crumbs, last page loaded, \Truxton\Client\TruxtonClient\TruxtonClient\PresentationCore\PageManager.cs
HomeViewModel.cs Adds the NavItems to the Main Menu \Truxton\Client\TruxtonClient\TruxtonClient\ViewModels\HomeViewModel.cs
ViewModelRegistrar.cs Registers the ViewModels so that the WorkspaceFactory can associate the View with the ViewModel \Truxton\Client\TruxtonClient\TruxtonClient\PresentationCore\ViewModelRegistrar.cs


Adding a New "Page"

This is an example of adding a new page in order to understand what is necessary.
  1. Create the View
  2. Create the ViewModel
  3. Register the ViewModel in the ViewModelRegistrar
  4. (Optional) Add the view to the Navigation

1. Create the View

Create the View-XAML as needed. In the View-Code, create the WorkspaceFactory. This will tie the View with the correct ViewModel. The ViewModel will need to be registered which will be explained in Step 3.
Example
Views/Home/Demo.xaml
      public class DemoFactory : ChildHomeFactory<Demo>
   {
       public override WorkSpace Generate(RouteValueDictionary parameters, ILifetimeScope scope)
       {
           var vm = scope.Resolve<DemoViewModel>();
           return new WorkSpace()
           {
               Scope = scope,
               View = scope.Resolve<Demo>(
                   new NamedParameter("viewModel", vm)
               ),
               ViewModel = vm
           };
       }
   }

2. Create the ViewModel

In the ViewModel, ensure the class extends BaseViewModel and that the Name is set in the constructor. If the name isn't set in the constructor, the Breadcrumbs will break.

3. Register the ViewModel in the ViewModelRegistrar

The Registrar is where the WorkspaceFactory looks for the specified ViewModel

4. (Optional) Add the view to the Navigation Menu

This step is optional. It's only needed if you need the View to be part of the main navigation menu.