--- source_files: - DTS Viewer/DTS.Viewer.Loader/ViewModel/ShellViewModel.cs generated_at: "2026-04-16T11:26:51.573043+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "4117e2f039d6caa8" --- # ShellViewModel Documentation ## 1. Purpose `ShellViewModel` serves as the main shell ViewModel for the DTS Viewer application loader. It acts as the primary orchestration layer for the application's UI shell, managing region navigation, notification/confirmation dialogs, and coordinating between the view layer and the Prism infrastructure (EventAggregator, RegionManager, UnityContainer). This class is the entry point for the shell's UI composition pattern, exposing regions for dynamic view injection and handling cross-component communication via events. --- ## 2. Public Interface ### Constructor ```csharp public ShellViewModel(IShellView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) ``` Initializes the shell ViewModel, sets the View's DataContext to itself, creates interaction requests, and subscribes to the `RaiseNotification` event. ### Properties | Property | Type | Description | |----------|------|-------------| | `View` | `IShellView` | The associated shell view instance. | | `NotificationRequest` | `InteractionRequest` | Interaction request for displaying notification dialogs. | | `ConfirmationRequest` | `InteractionRequest` | Interaction request for displaying confirmation dialogs. | | `Width` | `double` | Gets or sets the shell width. | | `Height` | `double` | Gets or sets the shell height. | | `IsMenuIncluded` | `bool` | Gets or sets whether the menu is included; raises `PropertyChanged`. | | `IsNavigationIncluded` | `bool` | Gets or sets whether navigation is included; raises `PropertyChanged`. | | `HeaderInfo` | `string` | Returns the constant string `"MainRegion"`. | | `IsBusy` | `bool` | Gets or sets the busy indicator state. | | `IsDirty` | `bool` | Read-only; always returns `false` (no setter logic). | | `ContextMainRegion` | `Object` | Gets or sets the content of the `MainRegion` on the View; raises `PropertyChanged` on set. | ### Methods ```csharp public void Initialize() public void Initialize(object parameter) public void Activated() ``` Empty implementations. No behavior executed. ```csharp public List GetRegions() ``` Returns all FrameworkElements named "Region" within the `MainShell` of the `ShellView` by calling `Utils.GetChildrenByName`. ```csharp public void Cleanup() public Task CleanupAsync() public Task InitializeAsync() public Task InitializeAsync(object parameter) ``` All throw `NotImplementedException`. ### Events ```csharp public event PropertyChangedEventHandler PropertyChanged ``` Standard `INotifyPropertyChanged` implementation. Raised via private `OnPropertyChanged(string propertyName)` method. --- ## 3. Invariants 1. **Singleton Scope**: The class is decorated with `[PartCreationPolicy(CreationPolicy.Shared)]`, ensuring a single shared instance per MEF container. 2. **DataContext Binding**: The View's `DataContext` is always set to the ViewModel instance during construction. 3. **Event Subscription**: The ViewModel subscribes to `RaiseNotification` event via `_eventAggregator.GetEvent().Subscribe(OnRaiseNotification)` during construction. 4. **View Casting**: Methods `GetRegions()` and `ContextMainRegion` property assume the `View` can be cast to `ShellView` concrete type. --- ## 4. Dependencies ### This Module Depends On: - `DTS.Common.Events` — `RaiseNotification` event type - `DTS.Common.Interface` — `IShellView`, `IViewerShellView`, `IViewerShellViewModel` interfaces - `DTS.Common.Utils` — `Utils.GetChildrenByName` static method - `DTS.Common.Base` — (imported but usage unclear from source) - `Microsoft.Practices.Prism.Events` — `IEventAggregator` - `Microsoft.Practices.Prism.Interactivity.InteractionRequest` — `InteractionRequest`, `Notification`, `Confirmation` - `Microsoft.Practices.Prism.Regions` — `IRegionManager` - `Microsoft.Practices.Prism.ViewModel` — (likely `NotificationObject` or similar base, though not used) - `Microsoft.Practices.Unity` — `IUnityContainer` - `System.ComponentModel.Composition` — MEF attributes ### Consumers (Inferred): - Any module resolving `IShellView` via MEF container - `RaiseNotification` event publishers (via `IEventAggregator`) --- ## 5. Gotchas 1. **NotImplementedException Methods**: `Cleanup()`, `CleanupAsync()`, `InitializeAsync()`, and `InitializeAsync(object parameter)` all throw `NotImplementedException`. Calling these will crash the application. 2. **Misleading XML Comment**: The constructor's documentation states it "Creates a new instance of the TechnologyDomainEditViewModel" — this is incorrect; it creates a `ShellViewModel`. 3. **Hardcoded View Cast**: `GetRegions()` and `ContextMainRegion` cast `View` to the concrete `ShellView` type, violating MVVM separation. If `IShellView` is implemented by a different view type, runtime `InvalidCastException` will occur. 4. **Dead Code**: `LoadViewer()` is defined but never called (commented out in constructor). It also casts `IViewerShellView` to `ShellView`, which appears to be a bug — `IViewerShellView` should likely map to a different view type. 5. **IsDirty Property**: The `IsDirty` property has no setter and always returns `false`. It is unclear if this is intentional or incomplete. 6. **Missing Base Class**: The commented-out inheritance (`//BaseViewModel`) suggests this class was refactored to not use a base ViewModel, but manually implements `INotifyPropertyChanged` instead.