Files
2026-04-17 14:55:32 -04:00

101 lines
5.4 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer/View/Navigation/ViewModel/NavigationViewModel.cs
generated_at: "2026-04-16T14:03:49.797600+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "a00beb6f74b53389"
---
# Documentation: NavigationViewModel
## 1. Purpose
`NavigationViewModel` is a Prism-based ViewModel responsible for managing the navigation region within the DTS Viewer application's shell. It serves as a mediator between the `INavigationView` and the application's navigation infrastructure, handling notification popups via `InteractionRequest` and providing a bindable `ContextNavigationRegion` property for dynamic content injection. The class inherits from `BaseViewModel<INavigationViewModel>` and implements `INavigationViewModel`.
---
## 2. Public Interface
### Constructor
```csharp
public NavigationViewModel(
INavigationView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
Initializes the ViewModel, sets the view's `DataContext` to itself, creates `NotificationRequest` and `ConfirmationRequest` instances, and subscribes to the `RaiseNotification` event via the `EventAggregator`.
### Properties
| Property | Type | Access | Description |
|----------|------|--------|-------------|
| `NavigationView` | `INavigationView` | `get` | Stores the associated view instance. |
| `NotificationRequest` | `InteractionRequest<Notification>` | `get` | Used to raise notification dialogs. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | `get` | Used to raise confirmation dialogs. |
| `ContextNavigationRegion` | `object` | `get/set` | Gets or sets the content of the `NavigationRegion` on the view. Raises `OnPropertyChanged` on set. |
| `HeaderInfo` | `string` | `get` | Returns the constant string `"NavigationRegion"`. |
| `IsBusy` | `bool` | `get/set` | **Throws `NotImplementedException`**. |
| `IsDirty` | `bool` | `get` | **Throws `NotImplementedException`**. |
### Methods
| Method | Return Type | Description |
|--------|-------------|-------------|
| `Initialize()` | `void` | Override. Empty implementation. |
| `Initialize(object parameter)` | `void` | Override. Casts `parameter` to `IShellViewModel` and assigns to `Parent` field. |
| `Activated()` | `void` | Override. **Throws `NotImplementedException`**. |
| `Cleanup()` | `void` | Override. **Throws `NotImplementedException`**. |
| `CleanupAsync()` | `Task` | **Throws `NotImplementedException`**. |
| `InitializeAsync()` | `Task` | Override. **Throws `NotImplementedException`**. |
| `InitializeAsync(object parameter)` | `Task` | Override. **Throws `NotImplementedException`**. |
### Events
| Event | Type | Description |
|-------|------|-------------|
| `PropertyChanged` | `PropertyChangedEventHandler` | Declared with `new` keyword, hiding the base implementation. Raised via `OnPropertyChanged`. |
---
## 3. Invariants
- `NavigationView` is set once in the constructor and never reassigned.
- `ContextNavigationRegion` always accesses `((NavigationView)NavigationView).NavigationRegion.Content`, requiring the concrete `NavigationView` type.
- `HeaderInfo` always returns the literal string `"NavigationRegion"`.
- The `RaiseNotification` event subscription is established at construction time and never unsubscribed.
- `Parent` is only set via `Initialize(object parameter)` and expects an `IShellViewModel` instance.
---
## 4. Dependencies
### This module depends on:
- `DTS.Common.Base``BaseViewModel<T>`
- `DTS.Common.Events``RaiseNotification` event, `NotificationContentEventArgs`, `NotificationContentEventArgsWithoutTitle` (implied by usage)
- `DTS.Common.Interface``INavigationViewModel`, `INavigationView`, `IShellViewModel`
- `Microsoft.Practices.Prism.Events``IEventAggregator`
- `Microsoft.Practices.Prism.Interactivity.InteractionRequest``InteractionRequest<T>`, `Notification`, `Confirmation`
- `Microsoft.Practices.Prism.Regions``IRegionManager`
- `Microsoft.Practices.Unity``IUnityContainer`
### What depends on this module:
- **Unclear from source alone** — The `IShellViewModel` interface suggests a parent shell consumes this ViewModel, but the exact consumers are not visible in this file.
---
## 5. Gotchas
1. **Many members throw `NotImplementedException`**: `IsBusy`, `IsDirty`, `Activated()`, `Cleanup()`, `CleanupAsync()`, `InitializeAsync()`, and `InitializeAsync(object parameter)` are all stubs that will crash if invoked. This indicates incomplete implementation.
2. **Broken abstraction in `ContextNavigationRegion`**: The property casts `INavigationView` to the concrete `NavigationView` type to access `NavigationRegion.Content`. This violates the interface contract and creates tight coupling.
3. **Incorrect XML documentation**: The constructor's XML comment states it "Creates a new instance of the TechnologyDoFrontEditViewModel" — this is a copy-paste error and does not match the actual class name.
4. **Event hiding**: The `PropertyChanged` event and `OnPropertyChanged` method are declared with `new`, hiding the base class implementation. This could lead to unexpected behavior if consumers expect the base event to fire.
5. **No event unsubscription**: The `RaiseNotification` event subscription in the constructor has no corresponding unsubscription in `Cleanup()` (which throws anyway), potentially causing memory leaks.
6. **Commented-out dead code**: A `GetRegions()` method is entirely commented out, suggesting unfinished or abandoned functionality.