https://github.com/calabonga/calabonga.wpf.mvvm.zones
Zones for UserControl binding fot WPF application with MVVM. It's like Regions in the Prism framework, but very simple.
https://github.com/calabonga/calabonga.wpf.mvvm.zones
Last synced: 6 months ago
JSON representation
Zones for UserControl binding fot WPF application with MVVM. It's like Regions in the Prism framework, but very simple.
- Host: GitHub
- URL: https://github.com/calabonga/calabonga.wpf.mvvm.zones
- Owner: Calabonga
- License: mit
- Created: 2024-09-23T06:30:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-15T08:06:08.000Z (over 1 year ago)
- Last Synced: 2025-10-01T17:18:13.160Z (10 months ago)
- Language: C#
- Size: 152 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Calabonga.Wpf.Mvvm.Zones
Zones is for UserControl binding for WPF application with MVVM. It's like Regions in the Prism framework, but more simple.
# How to use
There are a few simple steps:
1. Install nuget-package [`Calabonga.Wpf.Mvvm.Zones`](https://www.nuget.org/packages/Calabonga.Wpf.Mvvm.Zones/)
2. On the XAML where your zone will be use add namespace:
```diff
```
3. Create a markup in your page. For example, I've created two controls with zone names `MainZone` and `DetailsZone`.
```diff
+
+
```
4. Now we are ready to create some csharp objects. First of all we need views for Zone inherited from `IZoneView`:
```csharp
public interface IMainZoneView : IZoneView { }
public interface IDetailsZoneView : IZoneView { }
```
We should also create a views using this interfaces. For example for `IMainZoneView`:
```csharp
///
/// Interaction logic for MainZoneView.xaml
///
public partial class MainZoneView : UserControl, IMainZoneView
{
public MainZoneView()
{
InitializeComponent();
}
}
```
Then we need to viewModels for Zone inherited from `IZoneViewModel`:
```csharp
public interface IMainZoneViewModel : IZoneViewModel { }
public interface IDetailsZoneViewModel : IZoneViewModel { }
```
We should also create a viewModels using interfaces. Example:
```csharp
public partial class MainZoneViewModel : ZoneViewModelBase, IMainZoneViewModel
{
//skipped markup for brevity
}
```
5. Register ZoneManager in your Dependency Injection Container:
``` diff
+ services.AddZones();
```
6. Register your modules Views ans ViewModels interfaces in Dependency Injection Container:
```diff
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
```
7. Inject `ZoneManager` into your main ViewModel:
```csharp
public MainWindowViewModel(IZoneManager zoneManager, IVersionService versionService)
{
Title = $"WPF with MVVM (v{versionService.Version})";
_zoneManager = zoneManager;
}
```
8. Now you can open your components in the zones you want. For example, in the registered zones `MainZone` and `DetailsZone`:
```csharp
[RelayCommand]
private void OpenMain()
{
_zoneManager.ActivateZone("MainZone");
}
[RelayCommand]
private void OpenDetails()
{
_zoneManager.ActivateZone("DetailsName");
}
```
## Demo
You can find in this repository a `demo` project from where this snippets used.
### CommunityToolkit Messaging
DoubleClick on text in the Detail zone will send a message to the module in Main zone and to the Shell (see in window title).

### Remove module
DoubleClick on tne text in the Main zone will remove it self from zone where it opened.

## History
### 1.0.1 2024-10-21
IMvvmObjectFactory added to dependency injection registration fixed.
### 1.0.0 2024-09-26
First release