https://github.com/zeppaman/prism-wpf-tutorial
A simple tutorial to learn prims wpf basic
https://github.com/zeppaman/prism-wpf-tutorial
Last synced: 7 months ago
JSON representation
A simple tutorial to learn prims wpf basic
- Host: GitHub
- URL: https://github.com/zeppaman/prism-wpf-tutorial
- Owner: zeppaman
- License: gpl-3.0
- Created: 2018-11-09T17:17:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-09T17:54:31.000Z (almost 7 years ago)
- Last Synced: 2025-01-23T13:13:48.681Z (9 months ago)
- Language: C#
- Size: 127 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Prism Sample
This project is a tutorial for a quick prism project setup to show basic capabilities
- Modules
- Data Binding
- Region## Tutorial
Steps:1. install Prism Visual studio tools
2. Create a new Prism project
4. Create Module
5. Integrate modules
6. Configure Prism project## install Prism Visual studio tools

## Create a new Prism project


## Create Module
## Configure Prism project
### Register modules
Add project reference to the shell application. This can be also done using nuget on huge applications.
In `App.xaml.cs` add:
```cs
IModuleCatalog catalog;
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//get a local module catalog (or create your own implementation and register)
catalog = this.CreateModuleCatalog();
containerRegistry.RegisterInstance(catalog);
}protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
Type moduleCType = typeof(Module1Module);//Manually add here moduler, or use xml config, or directory loading
catalog.AddModule(InitializationMode.WhenAvailable);
catalog.AddModule(InitializationMode.WhenAvailable);
}
```### Add missing dependency on modules
### Register region from controls
Main windows act as wireframe, you can define many region:
```xml
```In module file you can define where contols will be placed at runtime:
```cs
public void OnInitialized(IContainerProvider containerProvider)
{
var regionManager = ServiceLocator.Current.GetInstance();
regionManager.RegisterViewWithRegion("HeaderRegion", typeof(ViewA));}
```
### Data bindingDefine in view model the property.
```cs
private string _message;
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}
```In xaml you simply need to bind to property
```xml```
### Add a command
In view model, you just need to define the delegate command.```cs
public ViewAViewModel()
{
this.TestCommand = new DelegateCommand(x => { ExecuteTestCommand(x); });
}private void ExecuteTestCommand(string x)
{
//DO Stuff here, x parameter is passed from Xaml
}public DelegateCommand TestCommand { get; private set; }
```In xaml is called as usual:
```xml
```### Add Controls dinamically into region
Components can be added at runtime simply using `regionmanager````cs
var regionManager = ServiceLocator.Current.GetInstance();
regionManager.AddToRegion("TabRegion", new TestView());
```