79 lines
5.4 KiB
Markdown
79 lines
5.4 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- Common/DTS.CommonCore/Base/View/BaseWindow.cs
|
||
|
|
- Common/DTS.CommonCore/Base/View/BaseView.cs
|
||
|
|
generated_at: "2026-04-16T02:51:29.370197+00:00"
|
||
|
|
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "e8beceb1bd7a7dfb"
|
||
|
|
---
|
||
|
|
|
||
|
|
# View
|
||
|
|
|
||
|
|
## Documentation: `DTS.Common.Base` View Base Classes
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 1. Purpose
|
||
|
|
This module provides foundational WPF view base classes (`BaseWindow` and `BaseView`) that standardize behavior for UI components in the application. These classes abstract common concerns—specifically, determining whether the underlying data model has unsaved changes (`IsDirty`) and retrieving a display-friendly header string (`HeaderInfo`) for tabbed interfaces—by delegating to interfaces implemented by the `DataContext`. They serve as reusable base classes to enforce consistency across views and reduce boilerplate in derived window and user control implementations.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 2. Public Interface
|
||
|
|
|
||
|
|
#### `BaseWindow`
|
||
|
|
- **Namespace**: `DTS.Common.Base`
|
||
|
|
- **Inherits**: `System.Windows.Window`, implements `IBaseWindow` (interface not shown in source; assumed to declare `IsDirty` and `HeaderInfo` members).
|
||
|
|
|
||
|
|
- **`public bool IsDirty { get; }`**
|
||
|
|
Returns `true` if the `DataContext` implements `IBaseWindowModel` *and* its `IsDirty` property is `true`; otherwise `false`. Returns `false` if `DataContext` is `null` or does not implement `IBaseWindowModel`.
|
||
|
|
|
||
|
|
- **`public string HeaderInfo { get; }`**
|
||
|
|
Returns the `HeaderInfo` string from the `DataContext` *if* it implements `IHeaderInfoProvider<string>`; otherwise returns `string.Empty`.
|
||
|
|
|
||
|
|
#### `BaseView`
|
||
|
|
- **Namespace**: `DTS.Common.Base`
|
||
|
|
- **Inherits**: `System.Windows.Controls.UserControl`, implements `IBaseView` (interface not shown in source; assumed to declare `IsDirty` and `HeaderInfo` members).
|
||
|
|
|
||
|
|
- **`public bool IsDirty { get; }`**
|
||
|
|
Returns `true` if the `DataContext` implements `IBaseViewModel` *and* its `IsDirty` property is `true`; otherwise `false`. Returns `false` if `DataContext` is `null` or does not implement `IBaseViewModel`.
|
||
|
|
|
||
|
|
- **`public string HeaderInfo { get; }`**
|
||
|
|
Returns the `HeaderInfo` string from the `DataContext` *if* it implements `IHeaderInfoProvider<string>`; otherwise returns `string.Empty`.
|
||
|
|
|
||
|
|
> **Note**: Both classes use identical logic for `HeaderInfo`, but differ in the interface they check for `IsDirty`: `IBaseWindowModel` (for `BaseWindow`) vs. `IBaseViewModel` (for `BaseView`). The interfaces `IBaseWindowModel` and `IBaseViewModel` are not defined in the provided source.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 3. Invariants
|
||
|
|
- `IsDirty` **always** returns `false` if `DataContext` is `null`.
|
||
|
|
- `IsDirty` **only** reads from the `DataContext`; it does not modify state.
|
||
|
|
- `HeaderInfo` **always** returns a non-null string (`string.Empty` if no provider is available).
|
||
|
|
- Both classes assume `DataContext` is set *before* `IsDirty` or `HeaderInfo` is accessed (though no explicit ordering requirement is enforced).
|
||
|
|
- The `IsDirty` logic is **passive**: it reflects the state of the `DataContext` but does not trigger updates or subscriptions.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 4. Dependencies
|
||
|
|
|
||
|
|
#### External Dependencies (from source):
|
||
|
|
- `System.Windows` (WPF framework) — required for `Window` and `UserControl` base types.
|
||
|
|
- Interfaces `IBaseWindowModel`, `IBaseViewModel`, and `IHeaderInfoProvider<string>` — referenced but not defined in the provided source. Their definitions must exist elsewhere in the codebase (likely in `DTS.Common.Base` or a related namespace).
|
||
|
|
|
||
|
|
#### Internal Dependencies:
|
||
|
|
- **Consumers**: Any WPF window or user control inheriting from `BaseWindow` or `BaseView` (e.g., custom `MainWindow : BaseWindow`).
|
||
|
|
- **Required by `DataContext`**:
|
||
|
|
- For `BaseWindow`: `DataContext` must implement `IBaseWindowModel` to participate in `IsDirty` reporting.
|
||
|
|
- For `BaseView`: `DataContext` must implement `IBaseViewModel` to participate in `IsDirty` reporting.
|
||
|
|
- For *both*: `DataContext` must implement `IHeaderInfoProvider<string>` to provide a non-empty `HeaderInfo`.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 5. Gotchas
|
||
|
|
- **Interface mismatch risk**: `BaseWindow` checks for `IBaseWindowModel`, while `BaseView` checks for `IBaseViewModel`. If a shared model implements both (or neither), behavior may be inconsistent or misleading.
|
||
|
|
- **No fallback or logging**: If `DataContext` is misconfigured (e.g., implements `IHeaderInfoProvider<string>` but returns `null`), `HeaderInfo` will still return `string.Empty`—no warning or exception occurs.
|
||
|
|
- **No change notification**: `IsDirty` is a synchronous read-only property. It does not raise `INotifyPropertyChanged` events, so UI bindings to `IsDirty` (e.g., for tab indicators) may not update automatically when the underlying model changes. Consumers must ensure `DataContext` raises `PropertyChanged` for `IsDirty` *and* re-evaluates the property (e.g., via `OnPropertyChanged(nameof(IsDirty))` in the view model).
|
||
|
|
- **Ambiguous naming**: The XML comments refer to “IBaseWindowModel” and “IBaseViewModel” but do not clarify their relationship or whether they overlap. Without seeing their definitions, it is unclear if a single `DataContext` could implement both.
|
||
|
|
- **No null-safety for `HeaderInfo`**: If `IHeaderInfoProvider<string>.HeaderInfo` returns `null`, the property will return `null` (not `string.Empty`). The code only guards against missing interface implementation, not interface contract violations.
|
||
|
|
|
||
|
|
> **None identified from source alone** for additional issues beyond those inferred from the logic and naming patterns.
|