9.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:34:31.801575+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | b5797f8ba3342db7 |
View
Documentation: RegionOfInterestChannels View Layer
1. Purpose
This module provides WPF UI infrastructure for rendering and interacting with a GridView-based view of region-of-interest (ROI) channel data. It enables dynamic column generation from a data source, per-column type-aware cell templating (e.g., TextBlock vs. CheckBox), column header interactivity (sorting, filtering, multi-select), and automatic column width adjustment for content-fit. It serves as the view layer in an MVVM pattern, implementing IRegionOfInterestChannelsView and delegating user actions to an associated IRegionOfInterestChannelsViewModel.
2. Public Interface
StateListIndexConverter
Namespace: RegionOfInterestChannels
Implements: IMultiValueConverter
Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
Converts a 2-element multi-value binding: expects[0] = IEnumerable<State>,[1] = int index. Returns theStateat the given index in the collection, ornullif inputs are invalid or index is out of bounds.
Note: Does not supportConvertBack.
RegionOfInterestChannelsView
Namespace: RegionOfInterestChannels
Implements: IRegionOfInterestChannelsView (partial class)
-
RegionOfInterestChannelsView()
Constructor; callsInitializeComponent(). -
GridViewColumnHeader_OnClick(object sender, RoutedEventArgs e)
Handles column header click events. Extracts theTagfrom the clicked header (supportingGridViewColumnHeaderSearchableorGridViewColumnHeaderSelectabletypes), then invokesvm.Sort(columnTag, true)on theDataContextif it implementsIRegionOfInterestChannelsViewModel. -
TextBlock_Loaded(object sender, RoutedEventArgs e)
Adjusts column width dynamically when aTextBlockin a cell is loaded and its content width exceeds the column’s current width (only ifWidthisdouble.NaN). Finds the column index via visual tree traversal and temporarily setsWidth = ActualWidth, then resets toNaNto trigger remeasurement.
RegionOfInterestChannelsDataTemplateSelector
Namespace: RegionOfInterestChannels
Inherits: DataTemplateSelector
-
TextBlockDataTemplate/CheckBoxDataTemplate
Public properties for the two templates to select between. -
SelectTemplate(object item, DependencyObject container)
Selects aDataTemplatebased on the cell’s underlying data type:- If
itemis aChannelEnabler, inspects the column’s header (as property name) to determine the property type onitem.- If type is
string→ returnsTextBlockDataTemplate; setsContentPresenter.Tagto the property value. - If type is
boolean(or other) → returnsCheckBoxDataTemplate; setsContentPresenter.Tagto the relative index of the column among boolean columns (i - checkStartColumn).
- If type is
- If
itemis not aChannelEnabler, defaults toTextBlockDataTemplate.
Note: Uses reflection (GetProperty,GetValue,GetType) on theitemandpresenter.Columns[i].Header. Assumes header text matches property names (with spaces removed).
- If
GridViewColumns (Static Class)
Namespace: RegionOfInterestChannels
Purpose: Attached property provider for configuring GridView columns dynamically from an ICollectionView source.
Attached Properties:
-
ColumnsSource(object)
Source collection (typicallyICollectionView) whose items define columns. Changing this clears and recreates columns. -
CellDataTemplateSelector(DataTemplateSelector)
Optional selector used to choose per-cell templates. -
CellDataTemplate(DataTemplate)
Fallback template for cells ifCellDataTemplateSelectorisnull. -
HeaderTextMember(string)
Property name on column source items whose value is used for column header text. -
DisplayMember(string)
Property name on column source items whose value is used as the binding path for cell content (currently commented out inCreateColumn).
Key Methods (Internal/Static):
-
CreateColumn(GridView gridView, object columnSource)
Constructs aGridViewColumnfrom acolumnSourceitem:- Reads
HeaderTextMemberandDisplayMemberfromgridView. - Determines column header type based on the column source item’s
MemberTypeproperty (retrieved viaGetPropertyValue(columnSource, "MemberType")):typeof(bool)→GridViewColumnHeaderSelectablewithSelectAllevent handler.typeof(string)→GridViewColumnHeaderSearchablewithSearchandClickHandlerevents.- Otherwise → plain
stringheader.
- Assigns
CellTemplateSelector,CellTemplate, and (commented-out)DisplayMemberBinding.
- Reads
-
GetPropertyValue(object obj, string propertyName)
Helper: uses reflection to getpropertyNamefromobj. -
GetArrayIndex(string fromString)
Parses an integer from a string like"SomeProperty[3]", returning-1on failure.
Event Handlers (Internal):
-
ColumnsSource_CollectionChanged(...)
SyncsgridView.Columnswith changes (Add,Remove,Replace,Move,Reset) in theColumnsSourcecollection. -
GridViewColumnHeaderSearchable_OnSearch(...)
Invokesvm.Filter(columnTag, searchTerm). -
GridViewColumnHeader_OnClick(...)
Invokesvm.Sort(columnTag, true)(same behavior asRegionOfInterestChannelsView.GridViewColumnHeader_OnClick). -
GridViewColumnHeaderSelectable_OnSelectAll(...)
Parses column index fromcolumnTag(e.g.,"Enabled[2]"), then invokesvm.SelectAll(columnIndex, isSelected).
3. Invariants
-
Column Source Contract:
Items in theColumnsSourcecollection must have:- A property named
"MemberType"(e.g.,typeof(string)ortypeof(bool)), used to determine header type. - Properties named by
HeaderTextMemberandDisplayMember(if set), or default tonull.
- A property named
-
Header Tag Format:
ForGridViewColumnHeaderSelectable, theTagmust be a string containing an array index in brackets (e.g.,"Enabled[0]") to be parsed byGetArrayIndex. -
StateListIndexConverterInput Expectation:
Exactly two values: anIEnumerable<State>and anint. Any deviation yieldsnull. -
ChannelEnablerAssumption:
RegionOfInterestChannelsDataTemplateSelector.SelectTemplateassumesitemis aChannelEnablerwhen inspecting property types. Behavior for other types is not defined in source. -
Column Width Adjustment Scope:
TextBlock_Loadedonly adjusts the first matchingContentPresenterin the row. If multipleTextBlocks exist per row, only the first is considered.
4. Dependencies
Dependencies of this module:
- WPF Framework:
System.Windows,System.Windows.Controls,System.Windows.Data,System.Windows.Media. - Common Libraries:
DTS.Common.Controls(forGridViewColumnHeaderSearchable,GridViewColumnHeaderSelectable)DTS.Common.Interface.RegionOfInterest.RegionOfInterestChannels(forIRegionOfInterestChannelsView,IRegionOfInterestChannelsViewModel)DTS.Common.Utils(forUtils.FindChild<T>)
Dependencies on this module:
IRegionOfInterestChannelsViewModelmust be implemented by theDataContextforRegionOfInterestChannelsViewto handle sorting, filtering, and selection.Statetype is used byStateListIndexConverter(imported from elsewhere in the codebase).ChannelEnablertype is used byRegionOfInterestChannelsDataTemplateSelector(imported from elsewhere).
5. Gotchas
-
ConvertBackis Unimplemented:
StateListIndexConverter.ConvertBackthrowsNotImplementedException. It is strictly a one-way converter. -
DisplayMemberBindingis Commented Out:
InCreateColumn, the line settingcolumn.DisplayMemberBindingis commented. Cell binding relies entirely onCellDataTemplateSelectororCellDataTemplate. This may cause confusion ifDisplayMemberis set but unused. -
Header Property Name Matching:
RegionOfInterestChannelsDataTemplateSelector.SelectTemplateusespresenter.Columns[i].Header.ToString().Replace(" ", "")to match property names. If headers contain non-alphanumeric characters beyond spaces, reflection will fail. -
MemberTypeProperty Requirement:
Column source items must expose a"MemberType"property (via reflection). If missing or non-Type,columnPropertyTypebecomesnull, causingcheckStartColumnto be set and defaulting toCheckBoxDataTemplate. -
Duplicate Event Handlers Risk:
ColumnsSource_CollectionChangedadds handlers toICollectionView.CollectionChangedbut does not deduplicate ifColumnsSourceis reassigned to the same collection instance. This could lead to multiple handler invocations per event. -
TextBlock_LoadedFragility:
Relies on a specific visual tree structure (GridViewRowPresenter→ContentPresenter→TextBlock). Changes to control templates may break the width adjustment logic. -
No Null-Safety for
e?.OriginalSource:
InGridViewColumnHeaderSelectable_OnSelectAll,(bool)(e?.OriginalSource ?? false)may throwInvalidCastExceptionife.OriginalSourceis not aboolornull.