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.
-
- Entry Point
- Navigation and Routing
- Databinding
- Dependency Injection
- Task Bar Icon
- Truxton CLI options
- How Reports are Displayed
Main Resources
| Resource
|
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
|
| View Directory
|
Contains the various Views
|
\Truxton\Client\TruxtonClient\TruxtonClient\Views\
|
| Templates Directory
|
Contains Templates which are additional XAML that may be used in each Views
|
\Truxton\Client\TruxtonClient\TruxtonClient\Templates\
|
| ViewModel Directory
|
Contains the various ViewModels for each view
|
\Truxton\Client\TruxtonClient\TruxtonClient\ViewModels\
|
Adding a New "Page"
- This is an example of adding a new page in order to understand what is necessary.
- Create the View
- Create the ViewModel
- Register the ViewModel in the ViewModelRegistrar
- (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.
| Demo.xaml.cs
|
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.
| DemoViewModel.cs
|
public class DemoViewModel : BaseViewModel
{
public PageFrameViewModel PageFrameViewModel { get; set; }
public class Context : IContext
{
public PageFrameViewModel PageFrameViewModel { get; set; }
}
readonly Context _ctx;
public DemoViewModel(Context ctx)
{
Name = "Demo";
PageFrameViewModel = ctx.PageFrameViewModel;
PageFrameViewModel.Label = "NewDemo";
}
|
3. Register the ViewModel in the ViewModelRegistrar
- The Registrar is where the WorkspaceFactory looks for the specified ViewModel
| ViewModelRegistrar.cs
|
builder.RegisterType<DemoViewModel>();
|
- This step is optional. It's only needed if you need the View to be part of the main navigation menu.
| HomeViewModel.cs
|
Add to the constructor
addNavItem(nameof(Views.Demo),
"New Nav Page",
Testing for learning!");
|