Files
DP44/enriched-qwen3-coder-next/Common/DTS.Common/Converters.md

338 lines
20 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- Common/DTS.Common/Converters/BooleanToBorderThicknessConverter.cs
- Common/DTS.Common/Converters/BooleanToBorderBrushConverter.cs
- Common/DTS.Common/Converters/BooleanToGreenBorderConverter.cs
- Common/DTS.Common/Converters/YesNoRadioButtonsConventer.cs
- Common/DTS.Common/Converters/BooleanOrMultiConverter.cs
- Common/DTS.Common/Converters/DateTimeWithMillisecondsToStringConverter.cs
- Common/DTS.Common/Converters/EnumVisibilityConverter.cs
- Common/DTS.Common/Converters/InverseEnumVisibilityConverter.cs
- Common/DTS.Common/Converters/ActiveContentConverter.cs
- Common/DTS.Common/Converters/FaultedTextConverter.cs
- Common/DTS.Common/Converters/TriggerTextConverter.cs
- Common/DTS.Common/Converters/TriggerColorConverter.cs
- Common/DTS.Common/Converters/FaultedColorConverter.cs
- Common/DTS.Common/Converters/DateConverter.cs
- Common/DTS.Common/Converters/NullableFloatConverter.cs
- Common/DTS.Common/Converters/InverseEnumEnabledConverter.cs
- Common/DTS.Common/Converters/IsLessThanConverter.cs
- Common/DTS.Common/Converters/ListToStringConverter.cs
- Common/DTS.Common/Converters/IsGreaterThanConverter.cs
- Common/DTS.Common/Converters/NonZeroToColorConverter.cs
- Common/DTS.Common/Converters/HeightConverter.cs
- Common/DTS.Common/Converters/ErrorToBooleanConverter.cs
- Common/DTS.Common/Converters/WidthConverter.cs
- Common/DTS.Common/Converters/StringListToVisibilityConverter.cs
- Common/DTS.Common/Converters/StatusToBorderThicknessConverter.cs
- Common/DTS.Common/Converters/ArrayVisibilityConverter.cs
- Common/DTS.Common/Converters/DSPStreamingFilterFrequencyConverter.cs
- Common/DTS.Common/Converters/ErrorToColorConverter.cs
- Common/DTS.Common/Converters/GreaterThanToBoolConverter.cs
- Common/DTS.Common/Converters/BooleanToColorConverter.cs
- Common/DTS.Common/Converters/BooleanToItalicFontStyleConverter.cs
- Common/DTS.Common/Converters/IntervalToVisibilityConverter.cs
- Common/DTS.Common/Converters/StatusToColorConverter.cs
- Common/DTS.Common/Converters/DiagStatusShuntColorConverter.cs
- Common/DTS.Common/Converters/DiagStatusOffsetColorConverter.cs
- Common/DTS.Common/Converters/InverseBooleanToOpacityConverter.cs
- Common/DTS.Common/Converters/ColorToSolidColorBrushConverter .cs
- Common/DTS.Common/Converters/BooleanAndToVisibiltyMultiConverter.cs
- Common/DTS.Common/Converters/BooleanOrToVisibilityMultiConverter.cs
- Common/DTS.Common/Converters/DoubleFromThousandthUnitToBaseUnit.cs
- Common/DTS.Common/Converters/BooleanToOpacityConverter.cs
- Common/DTS.Common/Converters/DASStatusArmTextConverter.cs
- Common/DTS.Common/Converters/RecordingModePreTriggerVisibilityConverter.cs
- Common/DTS.Common/Converters/EnumBooleanConverter.cs
- Common/DTS.Common/Converters/InitialOffsetToIEPESensorOffsetConverter.cs
- Common/DTS.Common/Converters/DASStatusColorConverter.cs
- Common/DTS.Common/Converters/DASStatusArmColorConverter .cs
- Common/DTS.Common/Converters/PercentConverter.cs
- Common/DTS.Common/Converters/NumericStringFormatConverter.cs
- Common/DTS.Common/Converters/VisibilityToRowHeightConverter.cs
- Common/DTS.Common/Converters/GroupImportErrorToStringConverter.cs
- Common/DTS.Common/Converters/GroupNameToVisibilityConverter.cs
- Common/DTS.Common/Converters/FilePathsToShortStringConverter.cs
- Common/DTS.Common/Converters/InverseBooleanConverter.cs
- Common/DTS.Common/Converters/EnumDescriptionTypeConverter.cs
generated_at: "2026-04-16T02:53:33.629685+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "e705305552eb4c3f"
---
# DTS.Common.Converters Module Documentation
## 1. Purpose
This module provides a collection of WPF `IValueConverter` and `IMultiValueConverter` implementations used for data binding in the DTS (Data Acquisition and Test System) application. These converters enable UI elements to dynamically reflect application state by transforming values (e.g., booleans, enums, numbers, dates, collections) into display-appropriate types such as `Visibility`, `Brush`, `Thickness`, `Opacity`, `FontStyle`, or formatted strings. They serve as a bridge between domain models and XAML views, reducing logic in view models and centralizing UI presentation rules.
## 2. Public Interface
All converters implement `IValueConverter` or `IMultiValueConverter` and reside in the `DTS.Common.Converters` namespace.
### `BooleanToBorderThicknessConverter`
- **Signature**: `public class BooleanToBorderThicknessConverter : IValueConverter`
- **Behavior**: Converts `true``1`, `false``2`. Used to visually distinguish active/inactive states via border thickness.
### `BooleanToBorderBrushConverter`
- **Signature**: `public class BooleanToBorderBrushConverter : IValueConverter`
- **Behavior**: Converts `true``BrushesAndColors.Brush_Warning`, `false`/`null``Brushes.Transparent`.
### `BooleanToGreenBorderConverter`
- **Signature**: `public class BooleanToGreenBorderConverter : IValueConverter`
- **Behavior**: Converts `true``BrushesAndColors.BrushApplicationStatusPowerGreen`, `false`/`null``Brushes.Transparent`.
### `YesNoRadioButtonsConventer` *(Note: Typo in class name)*
- **Signature**: `public class YesNoRadioButtonsConventer : IValueConverter`
- **Behavior**:
- `Convert`: Returns `true` if `parameter.ToString() == value.ToString()` (used to bind radio buttons to enum/string values).
- `ConvertBack`: Returns `parameter` if `value == true`, else `Binding.DoNothing`.
### `BooleanOrMultiConverter`
- **Signature**: `public class BooleanOrMultiConverter : IMultiValueConverter`
- **Behavior**: Returns `true` if **any** input boolean in the array is `true`; otherwise `false`. Throws `NotImplementedException` in `ConvertBack`.
### `DateTimeWithMillisecondsToStringConverter`
- **Signature**: `public class DateTimeWithMillisecondsToStringConverter : IValueConverter`
- **Behavior**: Converts `DateTime` to string using `Utils.Utils.FormatTimeStamp`. `ConvertBack` returns `null`.
### `EnumVisibilityConverter`
- **Signature**: `public class EnumVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Visible` if `value == parameter`, else `Visibility.Hidden`. `ConvertBack` returns `parameter` if `value == Visibility.Visible`, else `Binding.DoNothing`.
### `InverseEnumVisibilityConverter`
- **Signature**: `public class InverseEnumVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Hidden` if `value == parameter`, else `Visibility.Visible`. `ConvertBack` returns `parameter` if `value == Visibility.Hidden`, else `Binding.DoNothing`.
### `ActiveContentConverter`
- **Signature**: `public class ActiveContentConverter : IValueConverter`
- **Behavior**: Returns the input `ContentControl` unchanged if it is a `ContentControl`; otherwise `Binding.DoNothing`. Supports both directions.
### `FaultedTextConverter`
- **Signature**: `public class FaultedTextConverter : IValueConverter`
- **Behavior**: Converts `true``Strings.Strings.Faulted`, `false``Strings.Strings.FaultsClear`, `null`/non-bool → `Strings.Strings.FaultsClear`.
### `TriggerTextConverter`
- **Signature**: `public class TriggerTextConverter : IValueConverter`
- **Behavior**: Converts `true``Strings.Strings.Triggered`, `false``Strings.Strings.TriggerClear`, `null`/non-bool → `Strings.Strings.TriggerClear`.
### `TriggerColorConverter`
- **Signature**: `public class TriggerColorConverter : IValueConverter`
- **Behavior**: Converts `true``BrushesAndColors.Brush_ApplicationStatus_Failed.Color`, `false``BrushesAndColors.Brush_ApplicationStatus_Waiting.Color`, `null`/non-bool → `Brushes.Transparent.Color`.
### `FaultedColorConverter`
- **Signature**: `public class FaultedColorConverter : IValueConverter`
- **Behavior**: Converts `true``BrushesAndColors.Brush_ApplicationStatus_Failed.Color`, `false``BrushesAndColors.Brush_ApplicationStatus_Complete.Color`, `null`/non-bool → `Brushes.Transparent.Color`.
### `DateConverter`
- **Signature**: `public class DateConverter : IValueConverter`
- **Behavior**: Converts `DateTime``DateTime`, `null`/non-`DateTime``Strings.Strings.Table_NA`. `ConvertBack` behaves similarly.
### `NullableFloatConverter`
- **Signature**: `public class NullableFloatConverter : IValueConverter`
- **Behavior**: Converts `double``double`, `float``float`, `null`/other → `string.Empty`. `ConvertBack` returns `float` or `string.Empty`.
### `InverseEnumEnabledConverter`
- **Signature**: `public class InverseEnumEnabledConverter : IValueConverter`
- **Behavior**: Returns `false` if `value == parameter`, else `true`. Used for `IsEnabled`. `ConvertBack` returns `parameter` if `value == false`, else `Binding.DoNothing`.
### `IsLessThanConverter`
- **Signature**: `public class IsLessThanConverter : IValueConverter`
- **Behavior**: Compares `value < parameter` (both parsed as `decimal`). Defaults to `0` if parsing fails. Returns `bool`. `ConvertBack` returns `DependencyProperty.UnsetValue`.
### `ListToStringConverter`
- **Signature**: `public class ListToStringConverter : IValueConverter`
- **Behavior**: Converts `List<string>` → comma-separated string. Throws `InvalidOperationException` if `targetType != typeof(string)` or input is `null`. `ConvertBack` throws `NotImplementedException`.
### `IsGreaterThanConverter`
- **Signature**: `public class IsGreaterThanConverter : IValueConverter`
- **Behavior**: Compares `value > parameter` (both parsed as `decimal`). Defaults to `0` if parsing fails. Returns `bool`. `ConvertBack` returns `DependencyProperty.UnsetValue`.
### `NonZeroToColorConverter`
- **Signature**: `public class NonZeroToColorConverter : IValueConverter`
- **Behavior**:
- `"0"``BrushesAndColors.BrushApplicationStatusPowerGreen`
- `"---"``BrushesAndColors.BrushApplicationStatusPowerClear`
- Other → `BrushesAndColors.BrushApplicationStatusPowerRed`
### `HeightConverter`
- **Signature**: `public class HeightConverter : MarkupExtension, IValueConverter`
- **Behavior**: Returns `value - parameter` (both parsed as `double`/`int`). Implements `MarkupExtension` for XAML usage (singleton instance). `ConvertBack` returns `null`.
### `ErrorToBooleanConverter`
- **Signature**: `internal class ErrorToBooleanConverter : IValueConverter`
- **Behavior**: Returns `true` if `value` is `string.IsNullOrEmpty`, else `null`. `ConvertBack` throws `NotImplementedException`.
### `WidthConverter`
- **Signature**: `public class WidthConverter : MarkupExtension, IValueConverter`
- **Behavior**: Returns `value * parameter` (both parsed as `double`). Implements `MarkupExtension`. `ConvertBack` throws `NotImplementedException`.
### `StringListToVisibilityConverter`
- **Signature**: `public class StringListToVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Visible` if `List<string>` is non-empty, else `Visibility.Collapsed`. Throws `InvalidOperationException` if `targetType != typeof(Visibility)` or input is `null`. `ConvertBack` throws `NotImplementedException`.
### `StatusToBorderThicknessConverter`
- **Signature**: `public class StatusToBorderThicknessConverter : IValueConverter`
- **Behavior**: Maps `UIItemStatus` to border thickness: `None``1`, all others (`Success`, `Failed`, `Error`, `Warning`) → `2`. Non-`UIItemStatus``1`.
### `ArrayVisibilityConverter`
- **Signature**: `public class ArrayVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Hidden` if `null`, `Visibility.Visible` if `IList.Count > 0` or `Array.Length > 0`, else `Visibility.Visible`.
### `DSPStreamingFilterFrequencyConverter`
- **Signature**: `public class DSPStreamingFilterFrequencyConverter : IValueConverter`
- **Behavior**:
- `double.NaN``string.Empty`
- `0.0` (within `EPSILON = 0.00001`) → `Strings.Strings.Table_NA`
- Otherwise → formatted as `"F1"` (e.g., `"123.4"`)
- `ConvertBack`: Returns `parameter` if `value == true`, else `Binding.DoNothing`.
### `ErrorToColorConverter`
- **Signature**: `public class ErrorToColorConverter : IValueConverter`
- **Behavior**: Returns `Brushes.Red` if `value` is non-empty `string`, else `Brushes.Black`. Non-string input → `Brushes.Black`. `ConvertBack` throws `NotImplementedException`.
### `GreaterThanToBoolConverter`
- **Signature**: `public class GreaterEqualThanToBoolConverter : IValueConverter`
- **Behavior**: Returns `true` if `value >= parameter` for `int`, `double`, or `ushort` types. Returns `false` otherwise. `ConvertBack` returns `false`.
### `BooleanToColorConverter`
- **Signature**: `public class BooleanToColorConverter : IValueConverter`
- **Behavior**: Configurable via properties:
- `Inverted`: Inverts input boolean.
- `Background`: If `true`, returns `Brushes.Transparent` for `true`.
- `AttentionBrush`: If `true`, returns `BrushesAndColors.Brush_Attention` for `false`.
- `WarningBrush`: If `true`, returns `BrushesAndColors.Brush_Warning` for `false`.
- Default: `true``Brush_NoError`, `false``Brush_Error`.
### `BooleanToItalicFontStyleConverter`
- **Signature**: `public class BooleanToItalicFontStyleConverter : IValueConverter`
- **Behavior**: Converts `true``FontStyles.Italic`, `false`/`null``FontStyles.Normal`.
### `IntervalToVisibilityConverter`
- **Signature**: `public class IntervalToVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Visible` if `value >= parameter` (for `int`, `double`, `ushort`), else `Visibility.Collapsed`. `ConvertBack` returns `false`.
### `StatusToColorConverter`
- **Signature**: `public class StatusToColorConverter : IValueConverter`
- **Behavior**: Maps `UIItemStatus` to color:
- `None``Brushes.Black`
- `Success``Brush_ApplicationStatus_Complete`
- `Failed`/`Error``Brush_ApplicationStatus_Failed`/`Brushes.Red`
- `Warning``Brushes.OrangeRed`
- Default → `Brushes.Transparent`.
### `DiagStatusShuntColorConverter`
- **Signature**: `public class DiagStatusShuntColorConverter : IValueConverter`
- **Behavior**: Maps `DiagStatuses`:
- `NoResults``Brush_ApplicationStatus_Idle`
- `FailedShunt` bit set → `Brush_ApplicationStatus_Failed`
- Otherwise → `Brush_ApplicationStatus_Complete`
- Default → `Brush_ApplicationStatus_Idle`.
### `DiagStatusOffsetColorConverter`
- **Signature**: `public class DiagStatusOffsetColorConverter : IValueConverter`
- **Behavior**: Same logic as `DiagStatusShuntColorConverter`, but checks `FailedOffset` bit.
### `InverseBooleanToOpacityConverter`
- **Signature**: `public class InverseBooleanToOpacityConverter : IValueConverter`
- **Behavior**: Converts `true``1.0`, `false`/`null``0.5`.
### `ColorToSolidColorBrushConverter`
- **Signature**: `public class ColorToSolidColorBrushConverter : IValueConverter`
- **Behavior**: Converts `Color``SolidColorBrush`. Non-`Color` input → `null`. `ConvertBack` throws `NotImplementedException`.
### `BooleanAndToVisibilityMultiConverter`
- **Signature**: `public class BooleanAndToVisibilityMultiConverter : IMultiValueConverter`
- **Behavior**: Returns `Visibility.Visible` if **all** inputs are `true`. Supports `parameter` flags:
- `"FALSE"`: Invert logic (`false` → visible).
- `"HIDE"`: Use `Visibility.Hidden` instead of `Collapsed`.
- `ConvertBack` throws `NotImplementedException`.
### `BooleanOrToVisibilityMultiConverter`
- **Signature**: `public class BooleanOrToVisibilityMultiConverter : IMultiValueConverter`
- **Behavior**: Returns `Visibility.Visible` if **any** input is `true`. Same parameter flags as `BooleanAndToVisibilityMultiConverter`.
- `ConvertBack` throws `NotImplementedException`.
### `DoubleFromThousandthUnitToBaseUnit`
- **Signature**: `public class DoubleFromThousandthUnitToBaseUnit : IValueConverter`
- **Behavior**: Converts thousandths to base unit (e.g., mV → V): `value / 1000`. `ConvertBack`: `value * 1000`. `double.NaN``0D`.
### `BooleanToOpacityConverter`
- **Signature**: `public class BooleanToOpacityConverter : IValueConverter`
- **Behavior**: Converts `true``0.5`, `false`/`null``1.0`. Used for disabled/enabled visual feedback.
### `DASStatusArmTextConverter`
- **Signature**: `public class DASStatusArmTextConverter : IValueConverter`
- **Behavior**: Maps `DASStatuses` to text:
- `MissingNotBooted`, `BootedNotArmedYet`, `BootedNeverArmed`, `ReadyForDownload``Strings.Strings.Table_NA`/`Strings.Strings.NotArmed`
- `ArmedReady`, `ArmedButFailedDiag``Strings.Strings.Armed`
- Default → `Strings.Strings.Table_NA`.
### `RecordingModePreTriggerVisibilityConverter`
- **Signature**: `public class RecordingModePreTriggerVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Visible` if pre-trigger should be shown (i.e., `RecordingModes` is active or can program pre-trigger). `parameter = "True"` inverts result.
### `EnumBooleanConverter`
- **Signature**: `public class EnumBooleanConverter : IValueConverter`
- **Behavior**: Returns `true` if `value.Equals(parameter)`. `ConvertBack`: Returns `parameter` if `value == true`, else `Binding.DoNothing`.
### `InitialOffsetToIEPESensorOffsetConverter`
- **Signature**: `public class InitialOffsetToIEPESensorOffsetConverter : IValueConverter`
- **Behavior**: Converts millivolt offset to IEPE sensor offset (volts): `(milliUnit / 1000) + 12.25`. `ConvertBack`: `(unit - 12.25) * 1000`. `double.NaN``0D`.
### `DASStatusColorConverter`
- **Signature**: `public class DASStatusColorConverter : IValueConverter`
- **Behavior**: Maps `DASStatuses` to color:
- `MissingNotBooted``Brush_ApplicationStatus_Idle`
- `BootedNotArmedYet``Brush_ApplicationStatus_Busy`
- `BootedNeverArmed`, `ArmedButFailedDiag``Brush_ApplicationStatus_Failed`
- `ArmedReady`, `ReadyForDownload``Brush_ApplicationStatus_Complete`
- Default → `Brush_ApplicationStatus_Idle`.
### `DASStatusArmColorConverter`
- **Signature**: `public class DASStatusArmColorConverter : IValueConverter`
- **Behavior**: Maps `DASStatuses` to color:
- `MissingNotBooted`, `BootedNotArmedYet`, `BootedNeverArmed``Brush_ApplicationStatus_Failed`
- `ArmedReady``Brush_ApplicationStatus_Complete`
- `ArmedButFailedDiag``Brush_ApplicationStatus_Busy`
- `ReadyForDownload``Brush_ApplicationStatus_Idle`
- Default → `Brush_ApplicationStatus_Idle`.
### `PercentConverter`
- **Signature**: `public class PercentConverter : IValueConverter`
- **Behavior**: Converts `decimal?` → formatted string `"{value:F1}%"`. Defaults to `0` if `null`. `ConvertBack` throws `NotImplementedException`.
### `NumericStringFormatConverter`
- **Signature**: `public class NumericStringFormatConverter : IMultiValueConverter`
- **Behavior**: Converts first value (`int`/`double`/`float`/`decimal`) to string using format string from second value. `NaN``Strings.Strings.Table_NA`. `ConvertBack` throws `NotImplementedException`.
### `VisibilityToRowHeightConverter`
- **Signature**: `public class VisibilityToRowHeightConverter : DependencyObject, IValueConverter`
- **Behavior**:
- `Visibility.Collapsed``0`
- Other → `parameter` (default `0` if `null`)
- `InvertSource` property inverts `Visible``Collapsed` before conversion.
### `GroupImportErrorToStringConverter`
- **Signature**: `public class GroupImportErrorToStringConverter : IValueConverter`
- **Behavior**: Returns `GroupImportError.ExtraInfo` if input is non-null `GroupImportError`, else `string.Empty`. `ConvertBack` throws `NotImplementedException`.
### `GroupNameToVisibilityConverter`
- **Signature**: `public class GroupNameToVisibilityConverter : IValueConverter`
- **Behavior**: Returns `Visibility.Visible` if `value.ToString().Trim()` starts with `"Graph"`, else `Visibility.Collapsed`.
### `FilePathsToShortStringConverter`
- **Signature**: `public class FilePathsToShortStringConverter : IValueConverter`
- **Behavior**:
- `null`/empty array → `string.Empty`
- Multiple files → `Strings.Strings.MultipleFiles`
- Single file → `FileInfo.Name`
### `InverseBooleanConverter`
- **Signature**: `public class InverseBooleanConverter : IValueConverter`
- **Behavior**: Inverts boolean (via `bool.TryParse`). `null``false`. Supports two-way binding.
### `EnumDescriptionTypeConverter`
- **Signature**: `public class EnumDescriptionTypeConverter : EnumConverter`
- **Behavior**: Overrides `ConvertTo` to return localized enum descriptions (via `DescriptionAttribute