7.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T02:17:03.753064+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 0e615cefd8a8a763 |
Themes
Documentation: DTS.Common Theme & Style Utilities
1. Purpose
This module provides shared, reusable styling infrastructure for the application’s UI, specifically focusing on two concerns: (1) centralized access to theme-defined Brush and Color resources via static properties with caching to avoid repeated resource lookups, and (2) a centralized event handler for tooltip events that publishes help text via Prism’s IEventAggregator. It serves as a single source of truth for visual styling constants, decoupling UI components from explicit resource key strings and enabling consistent theming across the application. The module does not define styles itself but consumes them from external resource dictionaries (e.g., brushes.xaml and implicit theme dictionaries).
2. Public Interface
CommonStyles (partial class, non-static)
void ToolTipEventHandler(object sender, ToolTipEventArgs e)
Marks the tooltip event as handled (e.Handled = true) and publishes aHelpTextEventArginstance (containing the originalsenderandToolTipEventArgs) to theHelpTextEventvia theIEventAggregator. This enables decoupled help-text display logic elsewhere in the application.
BrushesAndColors (abstract, non-instantiable)
A static utility class exposing ~40 read-only properties returning cached Brush or Color resources. All properties follow the naming pattern Brush_* or Color_*. Key examples:
Brush_ApplicationTileExport→SolidColorBrushBrush_ApplicationStatus_Failed→SolidColorBrushBrush_Dimmed_Text→SolidColorBrushBrush_Table_AlternatingRowBackground→SolidColorBrushBrush_FlatControlPressedBackground→BrushBrush_Transparent→Brush(created on-demand asnew SolidColorBrush(Colors.Transparent))Brush_Error,Brush_Warning,Brush_Attention,Brush_NoError→SolidColorBrushBrush_Realtime_OSC_SELECTED,Brush_Realtime_METER_UNSELECTED, etc. →BrushBrush_ApplicationStatusPowerRed,Brush_ApplicationStatusPowerYellow,Brush_ApplicationStatusPowerGreen→SolidColorBrushColor_ActionBackground,Color_ItemForeground, etc. →Color(not cached; fetched fresh each call)
Note
: Properties are implemented with lazy initialization and caching (where applicable). The
BrushesAndColorsclass isabstractto prevent instantiation.
3. Invariants
- Resource Availability: All
Brush/Colorresources must be defined in the application’s resource dictionaries (e.g.,Themes/brushes.xamlor merged dictionaries). If a resource is missing,Application.Current.FindResource(...)will throw aResourceReferenceKeyNotFoundExceptionat runtime (not caught in the source). - Immutability: All retrieved
Brushinstances are frozen (Freeze()) to make them immutable and thread-safe for rendering. This is enforced via.Freeze()after retrieval. - Caching Semantics:
- Most
Brushproperties cache their value in a private static field and reuse it on subsequent calls. Colorproperties do not cache; they callApplication.Current.FindResource(...)every time.- The
_resourceDictionaryfield is shared across all resource lookups that fall back tobrushes.xaml, but is only initialized on first use for those specific properties.
- Most
- Null Safety: Some properties guard against null resources (e.g.,
Brush_FlatControlDisabledForeground,Brush_ApplicationStatus_Waiting) and returnnullif the resource is missing. Others do not (e.g.,Brush_Error), risking exceptions.
4. Dependencies
External Dependencies (Imports/Usings)
System.Windows→ WPF core types (Application,ResourceDictionary,Brush,SolidColorBrush,Colors).System.Windows.Controls→ToolTipEventArgs.Microsoft.Practices.ServiceLocation→ServiceLocator.Current.Microsoft.Practices.Prism.Events→IEventAggregator,IEvent.DTS.Common.Events→HelpTextEvent,HelpTextEventArg(consumed but not defined here).
Internal Dependencies
DTS.Common.Events.HelpTextEventandHelpTextEventArgmust be defined elsewhere inDTS.Common.Events.Themes/brushes.xaml→ Required resource dictionary for fallback lookups (used byBrush_NoError,Brush_Error,Brush_Warning,Brush_Attention).- Application-level resource dictionaries → Must define all referenced resource keys (e.g.,
"Brush_ApplicationStatus_Failed","Color_ActionBackground", etc.).
Consumers (Inferred)
- Any UI component needing consistent styling (e.g., tiles, tables, status indicators) likely references
BrushesAndColorsproperties directly in XAML or code-behind. - Any component needing help-text support on tooltips likely subscribes to
HelpTextEventand attachesCommonStyles.ToolTipEventHandlerto tooltip events.
5. Gotchas
- Theme Switching Incompatibility: As noted in the
BrushesAndColorsXML doc comment, static caching means brushes may become stale if the theme changes at runtime (e.g., via dynamic resource dictionary replacement). The comment suggests this is currently non-issue because themes are not actively used. - Inconsistent Caching Strategy:
Colorproperties do not cache, while mostBrushproperties do. This is likely unintentional and could lead to repeated resource lookups for colors. - Typo in Resource Key: In
Brush_ApplicationStatus_Failed_SystemProcess, the resource key is"Brush_ApplicationStauts_Failed_SystemProcess"(missing "a" in "Status"). This may cause runtime failures if the key is misspelled in the XAML resource dictionary. - Null Handling Inconsistency: Some properties (e.g.,
Brush_FlatControlDisabledForeground) returnnullif the resource is missing; others (e.g.,Brush_Error) do not check for null afterFindResource, risking exceptions. - Double Initialization Risk in
Brush_Warning: TheBrush_Warningproperty incorrectly assigns to_brushErrorinstead of_brushWarningin its getter (_brushError = ...). This is a bug: it overwrites the_brushErrorcache and returns the warning brush as_brushError, while_brushWarningremainsnull. - Thread Safety: While frozen brushes are thread-safe, the lazy initialization logic (e.g.,
if (null == _brush_X) ...) is not thread-safe. Concurrent access during first initialization could result in multiple lookups or race conditions. - Hardcoded Resource Paths: The fallback
ResourceDictionaryforBrush_NoError,Brush_Error, etc., uses a hardcoded pack URI (/DTS.Common;component/Themes/brushes.xaml). This assumes the dictionary is embedded as a resource in theDTS.Commonassembly.
None identified from source alone — except where explicitly called out above.