Files
DP44/enriched-partialglm/DTS Viewer/DTS.Viewer/View/Navigation/ViewModel.md
2026-04-17 14:55:32 -04:00

106 lines
5.8 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer/View/Navigation/ViewModel/NavigationViewModel.cs
generated_at: "2026-04-16T11:24:52.139730+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 events via `IEventAggregator` and exposing a `ContextNavigationRegion` property for dynamically setting navigation content. This class inherits from `BaseViewModel<INavigationViewModel>` and implements the `INavigationViewModel` interface.
---
## 2. Public Interface
### Constructor
```csharp
public NavigationViewModel(INavigationView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
```
Initializes the view model with its associated view and Prism infrastructure dependencies. Sets the view's `DataContext` to itself, initializes interaction requests, and subscribes to the `RaiseNotification` event.
### Properties
| Property | Type | Access | Description |
|----------|------|--------|-------------|
| `NavigationView` | `INavigationView` | `get; private set;` | The associated navigation view instance. |
| `NotificationRequest` | `InteractionRequest<Notification>` | `get; private set;` | Interaction request for displaying notifications. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | `get; private set;` | Interaction request for displaying confirmations. |
| `ContextNavigationRegion` | `object` | `get; set;` | Gets or sets the content of the `NavigationRegion` on the underlying view. Raises `OnPropertyChanged` on set. |
| `HeaderInfo` | `string` | `get;` | Returns the constant string `"NavigationRegion"`. |
| `IsBusy` | `bool` | `get; set;` | **Throws `NotImplementedException`** in both getter and setter. |
| `IsDirty` | `bool` | `get;` | **Throws `NotImplementedException`** in getter. |
### Events
```csharp
public new event PropertyChangedEventHandler PropertyChanged;
```
Hides the base class event. Raised via the private `OnPropertyChanged(string propertyName)` method.
### Methods
| Method | Return Type | Description |
|--------|-------------|-------------|
| `Initialize()` | `void` | Empty override; performs no initialization. |
| `Initialize(object parameter)` | `void` | Sets the `Parent` property by casting `parameter` to `IShellViewModel`. |
| `Activated()` | `void` | **Throws `NotImplementedException`**. |
| `Cleanup()` | `void` | **Throws `NotImplementedException`**. |
| `CleanupAsync()` | `Task` | **Throws `NotImplementedException`**. |
| `InitializeAsync()` | `Task` | **Throws `NotImplementedException`**. |
| `InitializeAsync(object parameter)` | `Task` | **Throws `NotImplementedException`**. |
### Private Methods
```csharp
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
```
Event handler for `RaiseNotification` events. Transforms `NotificationContentEventArgs` into a `NotificationContentEventArgs` (without title) and raises the `NotificationRequest` with separate content and title.
---
## 3. Invariants
- `NavigationView` is assigned in the constructor and never reassigned.
- `Parent` is only set via `Initialize(object parameter)` and must be castable to `IShellViewModel`.
- The `RaiseNotification` event subscription is established at construction time and remains active for the lifetime of the view model.
- `ContextNavigationRegion` assumes the underlying `NavigationView` can be cast to the concrete `NavigationView` type to access `NavigationRegion.Content`.
---
## 4. Dependencies
### This module depends on:
- `DTS.Common.Base` — Provides `BaseViewModel<T>`
- `DTS.Common.Events` — Provides `RaiseNotification` event and `NotificationContentEventArgs`
- `DTS.Common.Interface` — Provides `INavigationViewModel`, `INavigationView`, `IShellViewModel`
- `Microsoft.Practices.Prism.Events` — Provides `IEventAggregator`
- `Microsoft.Practices.Prism.Interactivity.InteractionRequest` — Provides `InteractionRequest<T>`, `Notification`, `Confirmation`
- `Microsoft.Practices.Prism.Regions` — Provides `IRegionManager`
- `Microsoft.Practices.Unity` — Provides `IUnityContainer`
### What depends on this module:
- Cannot be determined from source alone (no consumers visible in this file).
---
## 5. Gotchas
1. **Incomplete Implementation**: Multiple methods (`Activated`, `Cleanup`, `CleanupAsync`, `InitializeAsync`, `InitializeAsync(object parameter)`) and properties (`IsBusy`, `IsDirty`) throw `NotImplementedException`. This class appears to be partially implemented.
2. **Member Hiding**: The `new` keyword is used to hide base class members (`PropertyChanged`, `OnPropertyChanged`, `IsBusy`, `IsDirty`, `CleanupAsync`). This may indicate a design issue or conflict with the base `BaseViewModel<T>` implementation.
3. **Stale XML Documentation**: The constructor's XML comment states "Creates a new instance of the TechnologyDoFrontEditViewModel" — this appears to be a copy-paste error from another view model.
4. **Unsafe Cast in ContextNavigationRegion**: The property directly casts `INavigationView` to the concrete `NavigationView` type:
```csharp
((NavigationView)NavigationView).NavigationRegion.Content
```
This will throw an `InvalidCastException` at runtime if the injected view is not exactly of type `NavigationView`.
5. **Event Transformation Logic**: `OnRaiseNotification` creates a new `NotificationContentEventArgs` from the received event args, extracting `Message`, `MessageDetails`, and `Image` while separating `Title`. This transformation may lose data if additional properties exist on the source event args.