5.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:46:41.293810+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | b2bc34d167251ea0 |
Converters
Documentation: GroupChannelList.Converters Module
1. Purpose
This module provides WPF value converters used for UI data binding in the GroupChannelList module. Specifically, it enables conditional presentation logic—converting boolean values to UI properties such as width (for collapsing/expanding UI elements) and background color (for highlighting sensor-related items). These converters facilitate declarative UI behavior in XAML without requiring additional view-model logic.
2. Public Interface
BooleanToWidthConverter
-
Namespace:
GroupChannelList.Converters -
Type:
classimplementingIValueConverter -
Method:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)- Behavior: Converts a
boolinput to adoublewidth.- If
valueisnull, returns0. - If
parameteris provided and parses successfully as adouble, uses that value fortrue; otherwise defaults todouble.NaN. - Returns the parsed width for
true, and0forfalse.
- If
- Example usage in XAML:
Width="{Binding IsSensorActive, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=100}"
- Behavior: Converts a
-
Method:
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)- Behavior: Always throws
NotImplementedException. One-way conversion only.
- Behavior: Always throws
SensorIdBackgroundConverter
-
Namespace:
GroupChannelList.Converters -
Type:
classimplementingIValueConverter -
Field:
private static SolidColorBrush SensorIdBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xE3, 0xFB, 0xE1));- A frozen
SolidColorBrushwith ARGB color(0xFF, 0xE3, 0xFB, 0xE1)(light green, #E3FBE1).
- A frozen
-
Method:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)- Behavior: Converts a
boolinput to aBrush.- If
valueisnull, returnsBrushes.Transparent. - If
valueistrue, returnsSensorIdBrush(frozen for performance). - If
valueisfalse, returnsBrushes.Transparent. - Any exception during conversion logs the message via
Trace.WriteLineand returnsBrushes.Transparent.
- If
- Example usage in XAML:
Background="{Binding HasSensorId, Converter={StaticResource SensorIdBackgroundConverter}}"
- Behavior: Converts a
-
Method:
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)- Behavior: Always throws
NotImplementedException. One-way conversion only.
- Behavior: Always throws
3. Invariants
-
BooleanToWidthConverter:- Output is always
0or adouble(includingdouble.NaNifparameterparsing fails). parameteris optional; if missing or invalid,double.NaNis used fortrue.- No validation on
valuebeyond null-checking; non-boolvalues will cause a runtimeInvalidCastException(not caught).
- Output is always
-
SensorIdBackgroundConverter:SensorIdBrushis frozen after first use (via.Freeze()) to ensure thread-safety and performance.- Output is always a
Brush; specificallyBrushes.TransparentorSensorIdBrush. - Null or non-
boolinputs are handled gracefully (returnBrushes.Transparent), but exceptions during conversion are silently logged.
4. Dependencies
-
Dependencies on external frameworks:
System.Windows.Data(WPFIValueConverterinterface)System.Windows.Media(SolidColorBrush,Brushes)System.Diagnostics(Trace)System.Globalization(CultureInfo)
-
Dependencies on other modules:
- None inferred from source (no internal project references in imports).
- Used by XAML views in the
GroupChannelListmodule (inferred from namespace path).
-
Depended upon by:
- XAML UI elements in
DataPRO.Modules.Groups.GroupChannelList(e.g.,GroupChannelListView.xaml), where these converters are referenced as static resources.
- XAML UI elements in
5. Gotchas
-
BooleanToWidthConverter:ConvertBackis unimplemented—cannot be used in two-way bindings.parameterparsing is silent: invalid values (e.g.,"abc") result indouble.NaNwithout error.- Non-
boolinputs (e.g.,null,int,string) will throwInvalidCastExceptionat runtime (not caught).
-
SensorIdBackgroundConverter:SensorIdBrushis shared and frozen after first use; if frozen prematurely (e.g., before first conversion), subsequent calls are safe but the freeze is redundant.- Exception handling is minimal: only logs to
Trace, no user-facing error. - Assumes
valueisbool; non-boolinputs (e.g.,null,int) will throwInvalidCastException(not caught).
-
Both converters:
- One-way only (
ConvertBackthrowsNotImplementedException). - No support for culture-specific formatting (uses default
CultureInfobehavior). - No documentation of expected
targetTypeconstraints (assumes WPF expectsdouble/Brushoutputs).
- One-way only (
None identified beyond the above.