An open API service indexing awesome lists of open source software.

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

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
![](https://raw.githubusercontent.com/zeppaman/prism-wpf-tutorial/master/docs/2.install-plugin.png)
## Create a new Prism project
![](https://raw.githubusercontent.com/zeppaman/prism-wpf-tutorial/master/docs/0.add_blank_app.png)
![](https://raw.githubusercontent.com/zeppaman/prism-wpf-tutorial/master/docs/1.choose_di.png)
## Create Module
![](https://raw.githubusercontent.com/zeppaman/prism-wpf-tutorial/master/docs/4.addmodule.png)

## 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
![](https://raw.githubusercontent.com/zeppaman/prism-wpf-tutorial/master/docs/3.missingdependency.png)

### 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 binding

Define 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());
```