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

71 lines
5.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
source_files:
- Common/DTS.Common/obj/x86/Debug/Themes/CommonStyles.g.i.cs
- Common/DTS.Common/obj/x86/Debug/Themes/CommonStyles.g.cs
generated_at: "2026-04-16T02:57:35.324519+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "2e2061c5c6af1d0a"
---
# Themes
## Documentation: `DTS.Common.CommonStyles`
---
### 1. Purpose
This module defines a WPF `ResourceDictionary` subclass (`CommonStyles`) that encapsulates shared UI styles and event handlers for tooltips across the application. It is auto-generated from `Themes/CommonStyles.xaml` during the build process and serves as the runtime entry point for loading those styles into the WPF resource system. Its primary role is to ensure consistent tooltip behavior—specifically, attaching a common `ToolTipOpening` event handler (`ToolTipEventHandler`) to multiple named styles defined in the XAML source—without requiring manual wiring in application code.
---
### 2. Public Interface
The class `CommonStyles` is a partial class inheriting from `System.Windows.ResourceDictionary` and implementing `IComponentConnector` and `IStyleConnector`. It exposes only one *public* method:
- **`void InitializeComponent()`**
Initializes the component by loading the embedded XAML resource dictionary from `/DTS.Common;component/themes/commonstyles.xaml`. This method is idempotent: it checks `_contentLoaded` and returns early on subsequent calls. It must be called before the dictionary is used (typically invoked automatically by the WPF framework or in the constructor of a consuming class).
> **Note**: All other methods (`Connect(int, object)` for `IComponentConnector` and `IStyleConnector`) are *explicit interface implementations* and are not intended for direct public consumption. They are invoked internally by the WPF build/runtime infrastructure.
---
### 3. Invariants
- `_contentLoaded` is `false` initially and set to `true` on first call to `InitializeComponent()` or `IComponentConnector.Connect()`. Once `true`, it is never reset.
- `InitializeComponent()` must be called **exactly once** per instance before the dictionary is used; otherwise, styles may not be loaded.
- The `IStyleConnector.Connect()` implementation assumes exactly 12 styles (connection IDs 112) in `CommonStyles.xaml` each define a `ToolTipOpening` event handler. If the XAML changes (e.g., adds/removes styles), the generated code and XAML must be regenerated together to maintain correctness.
- All event setters attach to `FrameworkElement.ToolTipOpeningEvent` using the same handler: `this.ToolTipEventHandler`. The handler itself is not defined in this file—its implementation resides in the *other* partial part of `CommonStyles` (likely in `CommonStyles.xaml.cs`), which is not provided here.
---
### 4. Dependencies
- **Dependencies *of* this module**:
- `System.Windows.Application.LoadComponent()` — used to load the embedded XAML resource.
- `System.Windows.ResourceDictionary` — base type.
- `System.Windows.Markup.IComponentConnector`, `IStyleConnector` — required for WPFs build-time code generation contract.
- `System.Windows.Controls.ToolTipEventHandler` — delegate type for tooltip events.
- `System.Windows.EventSetter` — used to attach event handlers to styles.
- `Microsoft.Windows.Controls` — likely indicates dependency on Microsofts WPF Toolkit or similar (e.g., `Microsoft.Windows.Controls.DataVisualization` or `Charting`).
- **Dependencies *on* this module**:
- Any WPF application or library referencing `DTS.Common` that uses styles defined in `CommonStyles.xaml`.
- The `CommonStyles.xaml` file itself (source) — this generated code is tightly coupled to it. Changes to the XAML require regeneration.
---
### 5. Gotchas
- **Auto-generated code**: This file is auto-generated by `PresentationBuildTasks` (WPF build tasks). **Manual edits will be overwritten** on rebuild. Always modify `CommonStyles.xaml` (and its code-behind, if any) instead.
- **Missing handler definition**: The `ToolTipEventHandler` method is referenced but not defined in this file. Its implementation is assumed to exist in the corresponding `CommonStyles.xaml.cs` (not provided), which must be present at runtime—otherwise, a `MissingMethodException` will occur.
- **Hardcoded connection IDs**: The `IStyleConnector.Connect()` switch statement uses numeric IDs (112) that correspond to style definitions in `CommonStyles.xaml`. If styles are reordered, added, or removed in the XAML without regenerating, the event handlers may be attached to the wrong styles or not at all.
- **No public style keys exposed**: This module does not expose any public constants or properties for style keys (e.g., `x:Key="MyStyle"`). Consumers must know or inspect the XAML to reference styles.
- **No validation of `target` type**: The `IStyleConnector.Connect()` method casts `target` to `Style` without checking—passing a non-`Style` object will cause a runtime `InvalidCastException`.
> **None identified from source alone** beyond the above.
---
**Note**: Since the actual `CommonStyles.xaml` and `CommonStyles.xaml.cs` files are not provided, details about the specific styles, their keys, or the logic inside `ToolTipEventHandler` are inferred only from the generated codes structure and line references.