Files
DP44/docs/ai/Common/DTS.CommonCore/Converters.md
2026-04-17 14:55:32 -04:00

20 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.CommonCore/Converters/BooleanToBorderThicknessConverter.cs
Common/DTS.CommonCore/Converters/BooleanToBorderBrushConverter.cs
Common/DTS.CommonCore/Converters/BooleanOrMultiConverter.cs
Common/DTS.CommonCore/Converters/BooleanToGreenBorderConverter.cs
Common/DTS.CommonCore/Converters/DateTimeWithMillisecondsToStringConverter.cs
Common/DTS.CommonCore/Converters/EnumVisibilityConverter.cs
Common/DTS.CommonCore/Converters/InverseEnumVisibilityConverter.cs
Common/DTS.CommonCore/Converters/ActiveContentConverter.cs
Common/DTS.CommonCore/Converters/FaultedTextConverter.cs
Common/DTS.CommonCore/Converters/TriggerTextConverter.cs
Common/DTS.CommonCore/Converters/NullableFloatConverter.cs
Common/DTS.CommonCore/Converters/TriggerColorConverter.cs
Common/DTS.CommonCore/Converters/FaultedColorConverter.cs
Common/DTS.CommonCore/Converters/DateConverter.cs
Common/DTS.CommonCore/Converters/InverseEnumEnabledConverter.cs
Common/DTS.CommonCore/Converters/IsLessThanConverter.cs
Common/DTS.CommonCore/Converters/ListToStringConverter.cs
Common/DTS.CommonCore/Converters/IsGreaterThanConverter.cs
Common/DTS.CommonCore/Converters/NonZeroToColorConverter.cs
Common/DTS.CommonCore/Converters/HeightConverter.cs
Common/DTS.CommonCore/Converters/ErrorToBooleanConverter.cs
Common/DTS.CommonCore/Converters/WidthConverter.cs
Common/DTS.CommonCore/Converters/StringListToVisibilityConverter.cs
Common/DTS.CommonCore/Converters/StatusToBorderThicknessConverter.cs
Common/DTS.CommonCore/Converters/ArrayVisibilityConverter.cs
Common/DTS.CommonCore/Converters/ErrorToColorConverter.cs
Common/DTS.CommonCore/Converters/GreaterThanToBoolConverter.cs
Common/DTS.CommonCore/Converters/BooleanToColorConverter.cs
Common/DTS.CommonCore/Converters/BooleanToItalicFontStyleConverter.cs
Common/DTS.CommonCore/Converters/IntervalToVisibilityConverter.cs
Common/DTS.CommonCore/Converters/DiagStatusShuntColorConverter.cs
Common/DTS.CommonCore/Converters/DiagStatusOffsetColorConverter.cs
Common/DTS.CommonCore/Converters/InverseBooleanToOpacityConverter.cs
Common/DTS.CommonCore/Converters/StatusToColorConverter.cs
Common/DTS.CommonCore/Converters/ColorToSolidColorBrushConverter .cs
Common/DTS.CommonCore/Converters/BooleanAndToVisibiltyMultiConverter.cs
Common/DTS.CommonCore/Converters/BooleanOrToVisibilityMultiConverter.cs
Common/DTS.CommonCore/Converters/DoubleFromThousandthUnitToBaseUnit.cs
Common/DTS.CommonCore/Converters/BooleanToOpacityConverter.cs
Common/DTS.CommonCore/Converters/DASStatusArmTextConverter.cs
Common/DTS.CommonCore/Converters/EnumBooleanConverter.cs
Common/DTS.CommonCore/Converters/InitialOffsetToIEPESensorOffsetConverter.cs
Common/DTS.CommonCore/Converters/DASStatusColorConverter.cs
Common/DTS.CommonCore/Converters/DASStatusArmColorConverter .cs
Common/DTS.CommonCore/Converters/PercentConverter.cs
Common/DTS.CommonCore/Converters/NumericStringFormatConverter.cs
Common/DTS.CommonCore/Converters/VisibilityToRowHeightConverter.cs
Common/DTS.CommonCore/Converters/GroupImportErrorToStringConverter.cs
Common/DTS.CommonCore/Converters/GroupNameToVisibilityConverter.cs
Common/DTS.CommonCore/Converters/FilePathsToShortStringConverter.cs
Common/DTS.CommonCore/Converters/InverseBooleanConverter.cs
Common/DTS.CommonCore/Converters/EnumDescriptionTypeConverter.cs
Common/DTS.CommonCore/Converters/TestDataToRegionOfInterestMaximumConverter.cs
2026-04-17T15:26:50.716956+00:00 zai-org/GLM-5-FP8 1 3c372e9a540e3118

DTS.Common.Converters Documentation

1. Purpose

This module provides a comprehensive collection of WPF value converters for data binding transformations in the DTS application. It bridges the gap between domain models and UI presentation by converting values such as booleans, enums, numeric types, and collections into UI-appropriate representations like Visibility, Brush, Thickness, and formatted strings. The converters support common scenarios including conditional visibility, status indication colors, numeric comparisons, and localization-aware enum display.


2. Public Interface

Boolean Converters

Class Signature Behavior
BooleanToBorderThicknessConverter Convert(object, Type, object, CultureInfo) → object Returns 1 when input bool is true, 2 when false.
BooleanToBorderBrushConverter Convert(object, Type, object, CultureInfo) → object Returns BrushesAndColors.Brush_Warning when true, Brushes.Transparent when false or null.
BooleanToGreenBorderConverter Convert(object, Type, object, CultureInfo) → object Returns BrushesAndColors.BrushApplicationStatusPowerGreen when true, BrushesAndColors.BrushFlatControlDarkForeground when false or null.
BooleanToColorConverter Convert(object, Type, object, CultureInfo) → object Configurable via properties: Background, Inverted, AttentionBrush, WarningBrush. Returns color based on boolean state.
BooleanToItalicFontStyleConverter Convert(object, Type, object, CultureInfo) → object Returns FontStyles.Italic when true, FontStyles.Normal when false or null.
BooleanToOpacityConverter Convert(object, Type, object, CultureInfo) → object Returns 0.5 when true, 1 when false or null.
InverseBooleanToOpacityConverter Convert(object, Type, object, CultureInfo) → object Returns 1.0 when true, 0.5 when false or null.
InverseBooleanConverter Convert(object, Type, object, CultureInfo) → object Returns inverted boolean. ConvertBack also inverts. Returns false for null input.

Multi-Value Boolean Converters

Class Signature Behavior
BooleanOrMultiConverter Convert(object[], Type, object, CultureInfo) → object Returns true if any boolean in values is true. Returns false if any value is not a bool.
BooleanAndToVisibilityMultiConverter Convert(object[], Type, object, CultureInfo) → object Returns Visibility.Visible if all booleans are true. Supports parameter flags: "FALSE" inverts logic, "HIDE" uses Hidden instead of Collapsed.
BooleanOrToVisibilityMultiConverter Convert(object[], Type, object, CultureInfo) → object Returns Visibility.Visible if any boolean is true. Same parameter flags as BooleanAndToVisibilityMultiConverter.

Enum Converters

Class Signature Behavior
EnumVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Visible when value.Equals(parameter), otherwise Visibility.Hidden.
InverseEnumVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Hidden when value.Equals(parameter), otherwise Visibility.Visible.
EnumBooleanConverter Convert(object, Type, object, CultureInfo) → object Returns true when value.Equals(parameter). ConvertBack returns parameter when value.Equals(true).
InverseEnumEnabledConverter Convert(object, Type, object, CultureInfo) → object Returns false when value.Equals(parameter), otherwise true.
EnumDescriptionTypeConverter ConvertTo(ITypeDescriptorContext, CultureInfo, object, Type) → object Returns [Description] attribute value from enum, with localization lookup via Strings.Strings.ResourceManager. Includes static helper GetEnumDescription(Enum).

Status Converters

Class Signature Behavior
StatusToBorderThicknessConverter Convert(object, Type, object, CultureInfo) → object Converts UIItemStatus enum to thickness: None1, all others → 2.
StatusToColorConverter Convert(object, Type, object, CultureInfo) → object Converts UIItemStatus to Brush: None → Black, Success → Complete, Failed → Failed, Error → Red, Warning → OrangeRed.
FaultedTextConverter Convert(object, Type, object, CultureInfo) → object Returns Strings.Strings.Faulted when true, Strings.Strings.FaultsClear when false or non-bool.
FaultedColorConverter Convert(object, Type, object, CultureInfo) → object Returns Brush_ApplicationStatus_Failed.Color when true, Brush_ApplicationStatus_Complete.Color when false.
TriggerTextConverter Convert(object, Type, object, CultureInfo) → object Returns Strings.Strings.Triggered when true, Strings.Strings.TriggerClear when false or non-bool.
TriggerColorConverter Convert(object, Type, object, CultureInfo) → object Returns Brush_ApplicationStatus_Failed.Color when true, Brush_ApplicationStatus_Waiting.Color when false.

DAS/Diagnostic Status Converters

Class Signature Behavior
DASStatusColorConverter Convert(object, Type, object, CultureInfo) → object Converts DASStatuses enum to status brush (Idle, Busy, Failed, Complete).
DASStatusArmTextConverter Convert(object, Type, object, CultureInfo) → object Converts DASStatuses to localized arm status text (Table_NA, NotArmed, Armed).
DASStatusArmColorConverter Convert(object, Type, object, CultureInfo) → object Converts DASStatuses to arm-specific status colors.
DiagStatusShuntColorConverter Convert(object, Type, object, CultureInfo) → object Converts DiagStatuses to color, checking FailedShunt flag via bitwise AND.
DiagStatusOffsetColorConverter Convert(object, Type, object, CultureInfo) → object Converts DiagStatuses to color, checking FailedOffset flag via bitwise AND.

Numeric Converters

Class Signature Behavior
IsLessThanConverter Convert(object, Type, object, CultureInfo) → object Parses value and parameter as decimal, returns left < right. Returns false on parse failure.
IsGreaterThanConverter Convert(object, Type, object, CultureInfo) → object Parses value and parameter as decimal, returns left > right. Returns false on parse failure.
GreaterEqualThanToBoolConverter Convert(object, Type, object, CultureInfo) → object Returns value >= parameter for int, double, or ushort. Returns false for unsupported types.
IntervalToVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Visible when value >= parameter for int, double, or ushort.
DoubleFromThousandthUnitToBaseUnit Convert(object, Type, object, CultureInfo) → object Divides by 1000 (e.g., mV → V). ConvertBack multiplies by 1000. Returns 0D for NaN or non-double.
InitialOffsetToIEPESensorOffsetConverter Convert(object, Type, object, CultureInfo) → object Converts mV to V with IEPE midpoint offset: (mV / 1000) + 12.25. Includes static ConvertDouble(double) method.
PercentConverter Convert(object, Type, object, CultureInfo) → object Formats decimal as "{0:F1}%" using CurrentUICulture.
NumericStringFormatConverter Convert(object[], Type, object, CultureInfo) → object Multi-value converter. values[0] is number, values[1] is format string. Supports int, double, float, decimal. Returns Strings.Strings.Table_NA for NaN.

Visibility Converters

Class Signature Behavior
ArrayVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Visible if IList.Count > 0 or Array.Length > 0, otherwise Collapsed. Returns Hidden for null.
StringListToVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Visible if List<string>.Any(), otherwise Collapsed.
GroupNameToVisibilityConverter Convert(object, Type, object, CultureInfo) → object Returns Visibility.Visible if string starts with "Graph", otherwise Collapsed.
VisibilityToRowHeightConverter Convert(object, Type, object, CultureInfo) → object Returns 0 for Collapsed, otherwise returns parameter (or 0 if null). Supports InvertSource dependency property.

Dimension Converters

Class Signature Behavior
HeightConverter Convert(object, Type, object, CultureInfo) → object Returns value - parameter as double. Implements MarkupExtension with singleton pattern.
WidthConverter Convert(object, Type, object, CultureInfo) → object Returns value * parameter as double. Implements MarkupExtension with singleton pattern.

String/Text Converters

Class Signature Behavior
ListToStringConverter Convert(object, Type, object, CultureInfo) → object Joins List<string> with ", ". Throws InvalidOperationException for non-string target or null list.
DateConverter Convert(object, Type, object, CultureInfo) → object Returns DateTime if value is DateTime, otherwise Strings.Strings.Table_NA.
NullableFloatConverter Convert(object, Type, object, CultureInfo) → object Returns float value or string.Empty for non-float.
DateTimeWithMillisecondsToStringConverter Convert(object, Type, object, CultureInfo) → object Delegates to Utils.Utils.FormatTimeStamp().
ErrorToBooleanConverter Convert(object, Type, object, CultureInfo) → object Returns true if string is null/empty, null for non-string.
ErrorToColorConverter Convert(object, Type, object, CultureInfo) → object Returns SolidColorBrush(Colors.Red) if string not empty, SolidColorBrush(Colors.Black) otherwise.
FilePathsToShortStringConverter Convert(object, Type, object, CultureInfo) → object Returns file name for single path, Strings.Strings.MultipleFiles for multiple, string.Empty for empty/null.
GroupImportErrorToStringConverter Convert(object, Type, object, CultureInfo) → object Returns GroupImportError.ExtraInfo or string.Empty.

Other Converters

Class Signature Behavior
ActiveContentConverter Convert(object, Type, object, CultureInfo) → object Returns value if ContentControl, otherwise Binding.DoNothing. Bidirectional.
ColorToSolidColorBrushConverter Convert(object, Type, object, CultureInfo) → object Returns new SolidColorBrush(color) for Color input, null otherwise.
NonZeroToColorConverter Convert(object, Type, object, CultureInfo) → object Returns BrushApplicationStatusPowerGreen for "0", BrushApplicationStatusPowerClear for "---", BrushApplicationStatusPowerRed otherwise.
TestDataToRegionOfInterestMaximumConverter Convert(object[], Type, object, CultureInfo) → object Multi-value converter accepting 5 values: dataStart, dataEnd, PreTrigger, PostTrigger, RecordingMode. Returns appropriate maximum based on RecordingModes enum.

3. Invariants

  • Boolean converters: Input must be castable to bool or nullable bool; unexpected types may return default values or null.
  • Enum converters: The parameter must match the enum type for Equals() comparison to succeed.
  • BooleanOrMultiConverter and BooleanAndToVisibilityMultiConverter: All values in the array must be of type bool; presence of any non-bool results in false.
  • ListToStringConverter: Input must be List<string>; null or other types throw InvalidOperationException.
  • StringListToVisibilityConverter: Input must be List<string>; null throws InvalidOperationException.
  • HeightConverter and WidthConverter: Input and parameter must be convertible to double.
  • IsLessThanConverter and IsGreaterThanConverter: Values are parsed as decimal using the provided culture's NumberFormat.
  • TestDataToRegionOfInterestMaximumConverter: Requires exactly 5 values in specific order; returns double.PositiveInfinity if preconditions not met.
  • EnumDescriptionTypeConverter: Relies on [Description] attributes being present on enum fields.
  • VisibilityToRowHeightConverter: InvertSource property must be set before conversion occurs.

4. Dependencies

External Dependencies (Imports)

  • System.Windows.Data - IValueConverter, IMultiValueConverter, Binding
  • System.Windows - Visibility, DependencyProperty, DependencyObject, FontStyles, MarkupExtension
  • System.Windows.Media - Brush, Brushes, SolidColorBrush, Color
  • System.Windows.Controls - ContentControl
  • System.Globalization - CultureInfo
  • System.ComponentModel - EnumConverter, DescriptionAttribute, ITypeDescriptorContext

Internal Dependencies

  • DTS.Common.Base - Referenced by ActiveContentConverter (usage unclear from source)
  • DTS.Common.Enums - UIItemStatus, RecordingModes
  • DTS.Common.Interface.Hardware - DASStatuses, DiagStatuses
  • DTS.Common.Classes.Groups - GroupImportError
  • DTS.Common.Strings - Strings static class for localized strings
  • DTS.Common.BrushesAndColors - Static brush definitions
  • DTS.Common.Utils.Utils - FormatTimeStamp() method

Consumers

Unknown from source alone. These converters are designed for XAML data binding and would be consumed by Views/UserControls in a WPF application.


5. Gotchas

  1. Inconsistent null handling: BooleanToBorderThicknessConverter throws NullReferenceException on null input (direct cast), while BooleanToBorderBrushConverter handles null gracefully.

  2. Opacity semantics inverted between converters: BooleanToOpacityConverter returns 0.5 for true and 1 for false, while InverseBooleanToOpacityConverter returns 1.0 for true and 0.5 for false. The naming is counterintuitive.

  3. NonZeroToColorConverter uses string comparison: Checks value.ToString() == "0" rather than numeric comparison, which may produce unexpected results for numeric types.

  4. HeightConverter singleton pattern: Uses a static _instance field with lazy initialization via ?? operator, which is not thread-safe.

  5. ConvertBack not implemented consistently: Many converters return null or throw NotImplementedException for ConvertBack, making them one-way only. InverseBooleanConverter is an exception that supports two-way binding.

  6. GreaterEqualThanToBoolConverter filename mismatch: The file is named GreaterThanToBoolConverter.cs but the class is GreaterEqualThanToBoolConverter (with "Equal" in the name).

  7. NullableFloatConverter XML comment is incorrect: The XML doc says "Date converter that will display Table_NA when date is null" — this appears to be copy-pasted from DateConverter.

  8. IntervalToVisibilityConverter XML comment is incorrect: The XML doc mentions "converts between two values and a bool (a >= b)" which describes a different converter.

  9. ListToStringConverter throws on null: Unlike StringListToVisibilityConverter which throws, this could be handled more gracefully.

  10. TestDataToRegionOfInterestMaximumConverter fallthrough: Returns double.PositiveInfinity for unrecognized input configurations, which may cause UI issues if not handled by callers.

  11. BooleanToColorConverter property defaults: Properties Background, Inverted, AttentionBrush, WarningBrush default to false. These must be set in XAML as converter properties to change behavior.

  12. EnumDescriptionTypeConverter localization fallback: If Strings.Strings.ResourceManager.GetString() returns null/whitespace, falls back to the description attribute text directly.