43 lines
3.3 KiB
Markdown
43 lines
3.3 KiB
Markdown
---
|
|
source_files:
|
|
- Common/DTS.Common/RegionManager/RegionAdapters/StackPanelRegionAdapter.cs
|
|
- Common/DTS.Common/RegionManager/RegionAdapters/ViewerStackPanelRegionAdapter.cs
|
|
generated_at: "2026-04-17T16:07:30.415142+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "dae6287a6558dc90"
|
|
---
|
|
|
|
# RegionAdapters
|
|
|
|
### Purpose
|
|
This module provides Prism region adapters for `StackPanel` controls, enabling the Prism RegionManager to manage views within `StackPanel` containers. It allows dynamic addition and removal of UI elements in response to changes in the region's Views collection. Two nearly identical adapters are provided: `StackPanelRegionAdapter` and `ViewerStackPanelRegionAdapter`.
|
|
|
|
### Public Interface
|
|
|
|
**StackPanelRegionAdapter**
|
|
- `public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)` — Constructor accepting a behavior factory for region configuration.
|
|
- `protected override void Adapt(IRegion region, StackPanel regionTarget)` — Subscribes to `region.Views.CollectionChanged` and synchronizes the `StackPanel.Children` collection. Handles `NotifyCollectionChangedAction.Add` by adding `UIElement` items to `regionTarget.Children`, and `NotifyCollectionChangedAction.Remove` by removing elements that exist in the panel.
|
|
- `protected override IRegion CreateRegion()` — Returns a new `AllActiveRegion` instance.
|
|
|
|
**ViewerStackPanelRegionAdapter**
|
|
- `public ViewerStackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)` — Constructor accepting a behavior factory.
|
|
- `protected override void Adapt(IRegion region, StackPanel regionTarget)` — Identical implementation to `StackPanelRegionAdapter.Adapt`.
|
|
- `protected override IRegion CreateRegion()` — Returns a new `AllActiveRegion` instance.
|
|
|
|
### Invariants
|
|
- If `region` is `null`, `Adapt` returns immediately without attaching event handlers.
|
|
- Only `Add` and `Remove` collection change actions are handled; other actions (e.g., `Move`, `Replace`, `Reset`) are ignored.
|
|
- Elements are only removed from `regionTarget.Children` if `Contains(element)` returns `true`.
|
|
- Both adapters always create `AllActiveRegion`, meaning all views in the region are considered active.
|
|
|
|
### Dependencies
|
|
- **Depends on**: `Prism.Regions` (`RegionAdapterBase<T>`, `IRegion`, `IRegionBehaviorFactory`, `AllActiveRegion`), `System.Windows.Controls` (`StackPanel`), `System.Windows` (`UIElement`), `System.Collections.Specialized` (`NotifyCollectionChangedAction`, `NotifyCollectionChangedEventArgs`).
|
|
- **Depended on by**: Unclear from source alone—likely registered with Prism's region adapter mappings at application startup.
|
|
|
|
### Gotchas
|
|
- **Duplicate implementations**: `StackPanelRegionAdapter` and `ViewerStackPanelRegionAdapter` have identical implementations. The reason for two separate classes is unclear from source alone—possibly for different registration scopes or naming conventions in different application areas.
|
|
- **Missing collection actions**: `Reset`, `Move`, and `Replace` actions are not handled, which could cause synchronization issues if the Views collection undergoes those operations.
|
|
- **Closure capture quirk**: In the `Remove` case, a redundant local variable `var element = elementLoopVariable;` is assigned. This appears to be a historical artifact (possibly from a VB.NET conversion or older C# version) and has no functional effect in current C#.
|
|
|
|
--- |