Difference between revisions of "Navigation and Routing"
Jump to navigation
Jump to search
| (12 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
:# [[ Navigation and Routing ]] | :# [[ Navigation and Routing ]] | ||
:# [[ Databinding ]] | :# [[ Databinding ]] | ||
| + | :# [[ Dependency Injection ]] | ||
| + | :# [[ Task Bar Icon ]] | ||
| + | :# [[ Truxton CLI options ]] | ||
| + | :# [[ How Reports are Displayed ]] | ||
| + | :# [[ How Dialog Forms Work ]] | ||
| + | :# [[ Forms with Images ]] | ||
| + | :# [[ Images ]] | ||
| + | :# [[ Bookmarks ]] | ||
| − | == Main | + | == Main Resources== |
::{| class="wikitable" | ::{| class="wikitable" | ||
| − | ! | + | ! Resource |
! Summary | ! Summary | ||
! Path | ! Path | ||
| Line 24: | Line 32: | ||
| Registers the ViewModels so that the WorkspaceFactory can associate the View with the ViewModel | | Registers the ViewModels so that the WorkspaceFactory can associate the View with the ViewModel | ||
| \Truxton\Client\TruxtonClient\TruxtonClient\PresentationCore\ViewModelRegistrar.cs | | \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\ | ||
|- | |- | ||
|} | |} | ||
| Line 39: | Line 59: | ||
====1. Create the View==== | ====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. | :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. | ||
| + | <div style="display:flex;justify-content:center;"> | ||
| + | {| class="wikitable" | ||
| + | ! Demo.xaml.cs | ||
| + | |- | ||
| + | | | ||
| + | public class DemoFactory : ChildHomeFactory<Demo> | ||
| + | { | ||
| + | public override WorkSpace Generate(RouteValueDictionary parameters, ILifetimeScope scope) | ||
| + | { | ||
| + | <b>var vm = scope.Resolve<DemoViewModel>();</b> | ||
| + | return new WorkSpace() | ||
| + | { | ||
| + | Scope = scope, | ||
| + | View = scope.Resolve<Demo>( | ||
| + | new NamedParameter("viewModel", vm) | ||
| + | ), | ||
| + | ViewModel = vm | ||
| + | }; | ||
| + | } | ||
| + | } | ||
| + | |- | ||
| + | |} | ||
| + | </div> | ||
====2. Create the ViewModel==== | ====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. | :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. | ||
| + | <div style="display:flex;justify-content:center;"> | ||
| + | {| class="wikitable" | ||
| + | ! DemoViewModel.cs | ||
| + | |- | ||
| + | | | ||
| + | public class DemoViewModel : <b>BaseViewModel</b> | ||
| + | { | ||
| + | public PageFrameViewModel PageFrameViewModel { get; set; } | ||
| + | public class Context : IContext | ||
| + | { | ||
| + | public PageFrameViewModel PageFrameViewModel { get; set; } | ||
| + | } | ||
| + | readonly Context _ctx; | ||
| + | public DemoViewModel(Context ctx) | ||
| + | { | ||
| + | <b>Name = "Demo";</b> | ||
| + | PageFrameViewModel = ctx.PageFrameViewModel; | ||
| + | PageFrameViewModel.Label = "NewDemo"; | ||
| + | } | ||
| + | |- | ||
| + | |} | ||
| + | </div> | ||
====3. Register the ViewModel in the ViewModelRegistrar==== | ====3. Register the ViewModel in the ViewModelRegistrar==== | ||
:The Registrar is where the WorkspaceFactory looks for the specified ViewModel | :The Registrar is where the WorkspaceFactory looks for the specified ViewModel | ||
| + | <div style="display:flex;justify-content:center;"> | ||
| + | {| class="wikitable" | ||
| + | ! ViewModelRegistrar.cs | ||
| + | |- | ||
| + | | | ||
| + | builder.RegisterType<DemoViewModel>(); | ||
| + | |- | ||
| + | |} | ||
| + | </div> | ||
====4. (Optional) Add the view to the Navigation Menu==== | ====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. | :This step is optional. It's only needed if you need the View to be part of the main navigation menu. | ||
| + | <div style="display:flex;justify-content:center;"> | ||
| + | {| class="wikitable" | ||
| + | ! HomeViewModel.cs | ||
| + | |- | ||
| + | | Add to the constructor | ||
| + | addNavItem(nameof(Views.Demo), | ||
| + | "New Nav Page", | ||
| + | Testing for learning!"); | ||
| + | |- | ||
| + | |} | ||
| + | </div> | ||
Latest revision as of 11:28, 30 November 2021
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.
Contents
UI Guide Menu
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!");
|