Files
DP44/docs/ai/Common/DTS.Common/RegionManager/RegionAdapters.md
2026-04-17 14:55:32 -04:00

3.3 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common/RegionManager/RegionAdapters/StackPanelRegionAdapter.cs
Common/DTS.Common/RegionManager/RegionAdapters/ViewerStackPanelRegionAdapter.cs
2026-04-17T16:07:30.415142+00:00 zai-org/GLM-5-FP8 1 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#.