97 lines
6.0 KiB
Markdown
97 lines
6.0 KiB
Markdown
---
|
|
source_files:
|
|
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/View/StateListIndexConverter.cs
|
|
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/View/RegionOfInterestChannelsView.xaml.cs
|
|
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/View/RegionOfInterestChannelsDataTemplateSelector.cs
|
|
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/View/GridViewColumns.cs
|
|
generated_at: "2026-04-17T15:54:07.829323+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "3a91a38b574329b5"
|
|
---
|
|
|
|
# RegionOfInterestChannels View Module Documentation
|
|
|
|
## 1. Purpose
|
|
|
|
This module provides the WPF view layer for the Region of Interest Channels feature. It implements a dynamic, data-driven `GridView` system where columns are generated at runtime based on a source collection, with specialized column headers for searching (string columns) and select-all functionality (boolean columns). The module includes a `DataTemplateSelector` for rendering different cell types (text vs. checkbox), a multi-value converter for state lookup by index, and attached properties that enable declarative column configuration in XAML.
|
|
|
|
---
|
|
|
|
## 2. Public Interface
|
|
|
|
### StateListIndexConverter
|
|
**Implements:** `IMultiValueConverter`
|
|
|
|
| Method | Signature | Behavior |
|
|
|--------|-----------|----------|
|
|
| `Convert` | `object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)` | Expects exactly 2 values: `values[0]` as `IEnumerable<State>` and `values[1]` as `int` index. Returns the `State` element at that index, or `null` if validation fails. |
|
|
| `ConvertBack` | `object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)` | Throws `NotImplementedException`. |
|
|
|
|
---
|
|
|
|
### RegionOfInterestChannelsView
|
|
**Implements:** `IRegionOfInterestChannelsView`
|
|
|
|
| Method | Signature | Behavior |
|
|
|--------|-----------|----------|
|
|
| Constructor | `RegionOfInterestChannelsView()` | Calls `InitializeComponent()`. |
|
|
| `GridViewColumnHeader_OnClick` | `void GridViewColumnHeader_OnClick(object sender, RoutedEventArgs e)` | Extracts column tag from `GridViewColumnHeaderSearchable` or `GridViewColumnHeaderSelectable` (via sender or visual tree traversal), casts `DataContext` to `IRegionOfInterestChannelsViewModel`, and calls `vm.Sort(columnTag, true)`. |
|
|
| `TextBlock_Loaded` | `void TextBlock_Loaded(object sender, RoutedEventArgs e)` | Auto-expands column width if the loaded `TextBlock` is wider than the current column width. Forces re-measure by setting `Width` to `ActualWidth` then back to `double.NaN`. |
|
|
|
|
---
|
|
|
|
### RegionOfInterestChannelsDataTemplateSelector
|
|
**Inherits:** `DataTemplateSelector`
|
|
|
|
| Property | Type | Description |
|
|
|----------|------|-------------|
|
|
| `TextBlockDataTemplate` | `DataTemplate` | Template for string-type cells. |
|
|
| `CheckBoxDataTemplate` | `DataTemplate` | Template for boolean-type cells. |
|
|
|
|
| Method | Signature | Behavior |
|
|
|--------|-----------|----------|
|
|
| `SelectTemplate` | `DataTemplate SelectTemplate(object item, DependencyObject container)` | For `ChannelEnabler` items: traverses the visual tree to find the column index, uses reflection to get the property type from the column header, and returns the appropriate template. Sets `container.Tag` to either the property value (for strings) or the column offset index (for booleans). Returns `TextBlockDataTemplate` for non-`ChannelEnabler` items. |
|
|
|
|
---
|
|
|
|
### GridViewColumns (Static Class)
|
|
Provides attached properties for dynamic `GridView` column generation.
|
|
|
|
| Attached Property | Type | Target | Description |
|
|
|-------------------|------|--------|-------------|
|
|
| `ColumnsSource` | `object` | `GridView` | Source collection for dynamic column generation. Changes trigger column creation/removal. |
|
|
| `CellDataTemplateSelector` | `DataTemplateSelector` | `GridView` | Selector used to choose cell templates. Takes precedence over `CellDataTemplate`. |
|
|
| `CellDataTemplate` | `DataTemplate` | `GridView` | Default cell template. |
|
|
| `HeaderTextMember` | `string` | `GridView` | Property name on column source items to use for header text. |
|
|
| `DisplayMember` | `string` | `GridView` | Property name for display binding (currently commented out in implementation). |
|
|
|
|
| Private Method | Behavior |
|
|
|----------------|----------|
|
|
| `ColumnsSourceChanged` | Clears existing columns, removes old handlers, adds new handlers, and creates columns from the new source. |
|
|
| `CreateColumn` | Creates a `GridViewColumn` with header type determined by `MemberType`: `bool` → `GridViewColumnHeaderSelectable`, `string` → `GridViewColumnHeaderSearchable`, default → plain string. Wires up `SelectAll`, `Search`, and `ClickHandler` events. |
|
|
| `ColumnsSource_CollectionChanged` | Handles `Add`, `Move`, `Remove`, `Replace`, `Reset` actions to synchronize `GridView.Columns` with the source collection. |
|
|
| `GetArrayIndex` | Parses an array index from a string in format `...[n]...`. Returns `-1` on parse failure. |
|
|
|
|
---
|
|
|
|
## 3. Invariants
|
|
|
|
1. **StateListIndexConverter input contract:** `values` must be non-null, have length exactly 2, `values[0]` must be `IEnumerable<State>`, `values[1]` must be `int`, and the index must be within bounds of the collection. Violation returns `null`.
|
|
|
|
2. **GridViewColumns registration:** The static dictionary `_gridViewsByColumnsSource` maintains a mapping from `ICollectionView` to `List<GridView>`. All `GridView`s sharing the same `ColumnsSource` will be synchronized on collection changes.
|
|
|
|
3. **Column header type mapping:** Column headers are created based on `MemberType` property of the column source:
|
|
- `typeof(bool)` → `GridViewColumnHeaderSelectable`
|
|
- `typeof(string)` → `GridViewColumnHeaderSearchable`
|
|
- Other → plain `string` header
|
|
|
|
4. **Template precedence:** In `CreateColumn`, the comment explicitly states: `selector < template < displaymember` (selector takes highest precedence).
|
|
|
|
5. **DataTemplateSelector column detection:** `RegionOfInterestChannelsDataTemplateSelector.SelectTemplate` assumes the column header's `ToString()` (with spaces removed) matches a property name on `ChannelEnabler`.
|
|
|
|
---
|
|
|
|
## 4. Dependencies
|
|
|
|
### This |