--- source_files: - DTS Viewer/DTS.Viewer/Modules/Main/View/MainView.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/ViewerShellView.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/MainViewLite.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/ExportMainView.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/ViewerMainView.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/ExportMainViewGrid.xaml.cs - DTS Viewer/DTS.Viewer/Modules/Main/View/ViewerMainViewGrid.xaml.cs generated_at: "2026-04-16T11:26:12.276849+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "a7a3a3c725d7b68b" --- # DTS Viewer Main Views Documentation ## 1. Purpose This module contains the WPF view code-behind files for the main window and viewer components of the DTS Viewer application. It provides multiple view variants (standard, lite, export, and viewer modes) that implement a view-first MVVM architecture using Prism. The views handle UI initialization, event subscription for graph loading notifications, and PDF/image export functionality. These views serve as the visual containers for the application's primary user interface elements. --- ## 2. Public Interface ### MainView ```csharp public partial class MainView : IMainView ``` - **Constructor**: `MainView()` - Initializes the WPF component via `InitializeComponent()`. - Implements `IMainView` interface from `DTS.Common.Interface`. ### ViewerShellView ```csharp public partial class ViewerShellView : IViewerShellView ``` - **Constructor**: `ViewerShellView()` - Initializes the WPF component via `InitializeComponent()`. - Implements `IViewerShellView` interface from `DTS.Common.Interface`. ### MainViewLite ```csharp public partial class MainViewLite : IMainViewerView ``` - **Constructor**: `MainViewLite()` - Initializes the WPF component via `InitializeComponent()`. - Implements `IMainViewerView` interface from `DTS.Common.Interface`. ### ExportMainView ```csharp public partial class ExportMainView : IExportMainView ``` - **Constructor**: `ExportMainView()` - Initializes the WPF component via `InitializeComponent()`. - Implements `IExportMainView` interface from `DTS.Common.Interface`. ### ViewerMainView ```csharp public partial class ViewerMainView : IViewerMainView ``` - **Constructor**: `ViewerMainView()` - Initializes the WPF component via `InitializeComponent()`. - Implements `IViewerMainView` interface from `DTS.Common.Interface`. - Contains commented-out code for AvalonDock layout serialization/deserialization (referencing `DockManager`, `XmlLayoutSerializer`, and `DataProViewerAvalonDock.config`). ### ExportMainViewGrid ```csharp public partial class ExportMainViewGrid : IExportMainViewGrid ``` - **Constructor**: `ExportMainViewGrid()` - Initializes component and subscribes to `Loaded` event. - Implements `IExportMainViewGrid` interface from `DTS.Common.Interface`. - **Public Method**: `int SaveToPDF(string directory, string pdfFileName)` - Renders the view to PDF and PNG files. Returns `> 0` on success, `< 0` on failure, or `0` if `MainShell` is not yet rendered. - **Private Property**: `IEventAggregator _eventAggregator` - Resolved from container on load. - **Private Method**: `void SetFocus()` - Empty implementation (no operation). - **Private Method**: `void ExportMainViewGrid_Loaded(object sender, RoutedEventArgs e)` - Resolves `IEventAggregator` and subscribes to `GraphLoadedCountNotification`. - **Private Method**: `void OnGraphLoadedCountNotification(GraphLoadedCountNotificationArg arg)` - Delays 3 seconds then invokes `SetFocus` via dispatcher. ### ViewerMainViewGrid ```csharp public partial class ViewerMainViewGrid : IViewerMainViewGrid ``` - **Constructor**: `ViewerMainViewGrid()` - Initializes component and subscribes to `Loaded` event. - Implements `IViewerMainViewGrid` interface from `DTS.Common.Interface`. - **Public Method**: `int SaveToPDF(string directory, string pdfFileName)` - Renders the view to PDF and PNG files. Returns `> 0` on success, `< 0` on failure, or `0` if `MainShell` is not yet rendered. - **Private Property**: `IEventAggregator _eventAggregator` - Resolved from container on load. - **Private Method**: `void SetFocus()` - Selects and focuses `chartOptTab` element. - **Private Method**: `void ViewerMainViewGrid_Loaded(object sender, RoutedEventArgs e)` - Resolves `IEventAggregator` and subscribes to `GraphLoadedCountNotification`. - **Private Method**: `void OnGraphLoadedCountNotification(GraphLoadedCountNotificationArg arg)` - Validates `DataContext` matches `arg.ParentVM`, delays 3 seconds, then invokes `SetFocus` via dispatcher. --- ## 3. Invariants - All views must call `InitializeComponent()` in their constructor (WPF code-behind requirement). - `SaveToPDF` requires `pdfFileName` to end with `.pdf` extension; otherwise returns `-1`. - `SaveToPDF` requires both `directory` and `pdfFileName` to be non-null and non-empty; otherwise returns `-1`. - `SaveToPDF` returns `0` if `MainShell.DesiredSize.Height` or `MainShell.DesiredSize.Width` is `0` (control not yet rendered). - `OnGraphLoadedCountNotification` only processes the event if `DataContext` is non-null and matches `arg.ParentVM` (cast to `IBaseViewModel`). - Event subscription to `GraphLoadedCountNotification` occurs only after the `Loaded` event fires (ensures `IEventAggregator` is available). - PDF export renders at 300 DPI resolution. - PNG export is generated alongside PDF with `.pdf` extension replaced by `.png`. --- ## 4. Dependencies ### External Dependencies - **Prism.Events** - `IEventAggregator` for pub/sub event messaging. - **Prism.Ioc** - `ContainerLocator` for service location. - **C1.WPF.Pdf** - `C1PdfDocument` for PDF generation (ComponentOne library). - **System.Windows** - WPF core types (`RoutedEventArgs`, `Visual`, `Dispatcher`, etc.). - **System.Windows.Media** - `RenderTargetBitmap`, `WriteableBitmap`, `PixelFormats`, `VisualTreeHelper`. - **System.Windows.Media.Imaging** - Bitmap rendering types. ### Internal Dependencies - **DTS.Common.Interface** - Interface definitions (`IMainView`, `IViewerShellView`, `IMainViewerView`, `IExportMainView`, `IViewerMainView`, `IExportMainViewGrid`, `IViewerMainViewGrid`). - **DTS.Common.Base** - `IBaseViewModel` base interface. - **DTS.Common.Events** - `GraphLoadedCountNotification` event and `GraphLoadedCountNotificationArg` argument class. - **DTS.Common.Utilities.Logging** - `APILogger.LogException(Exception)` for error logging. - **DTS.Common.Utils.PNGImageUtil** - `SaveImage(FrameworkElement, string)` static method for PNG export. ### Consumers - Unknown from source alone. These views are likely instantiated by a Prism bootstrapper or module initialization logic. --- ## 5. Gotchas 1. **Hardcoded 3-second delay**: Both `ExportMainViewGrid` and `ViewerMainViewGrid` use `Thread.Sleep(TimeSpan.FromSeconds(3))` before setting focus. This is a magic number with no configuration, potentially causing timing issues on slower systems. 2. **Empty SetFocus in ExportMainViewGrid**: The `SetFocus()` method in `ExportMainViewGrid` is empty, making the 3-second delayed focus operation a no-op. This may be intentional or dead code. 3. **Commented-out AvalonDock code**: `ViewerMainView` contains significant commented-out code for layout serialization using `XmlLayoutSerializer` and a `DockManager` element. This suggests either incomplete feature implementation or removed functionality that wasn't cleaned up. 4. **Multiple ReSharper disable directives**: `ExportMainView`, `ViewerMainView`, `ExportMainViewGrid`, and `ViewerMainViewGrid` all suppress multiple ReSharper inspections, which may mask potential code quality issues. 5. **Namespace inconsistency**: All files declare namespace `DTS.Viewer` despite residing in different subdirectories (e.g., `Modules/Main/View/`). This is intentional but may cause confusion when locating files. 6. **Event subscription without unsubscription**: Neither `ExportMainViewGrid` nor `ViewerMainViewGrid` unsubscribe from `GraphLoadedCountNotification`. This could cause memory leaks if views are created/destroyed frequently. 7. **PDF return value semantics**: The `SaveToPDF` method uses a tri-state return value (`>0`, `0`, `<0`) which is documented but unconventional. Callers must check for `> 0` rather than a simple boolean. 8. **Silent exception handling**: `SaveToPDF` catches all exceptions, logs them via `APILogger.LogException`, and returns `-1`. The caller receives no exception details.