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

2.8 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/DataPRO/RegionAdapters/StackPanelRegionAdapter.cs
2026-04-17T16:29:20.553191+00:00 zai-org/GLM-5-FP8 1 0b1fef2bce493cf0

RegionAdapters

Purpose

This module provides a Prism region adapter for StackPanel controls, enabling the Prism region navigation framework to manage child elements within a StackPanel. It bridges the gap between Prism's region management system and WPF's StackPanel by synchronizing the region's views collection with the panel's visual children.

Public Interface

StackPanelRegionAdapter (class, inherits RegionAdapterBase<StackPanel>)

  • StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) - Constructor accepting the region behavior factory required by the base class.
  • protected override void Adapt(IRegion region, StackPanel regionTarget) - Subscribes to the region's Views.CollectionChanged event and synchronizes additions and removals with the StackPanel.Children collection. Handles NotifyCollectionChangedAction.Add and NotifyCollectionChangedAction.Remove actions; other actions are ignored.
  • protected override IRegion CreateRegion() - Returns a new AllActiveRegion instance, indicating all views in this region are considered active.

Invariants

  • The region parameter in Adapt() may be null; the method returns early without side effects in this case.
  • Only Add and Remove collection change actions are handled; Replace, Reset, and Move actions are silently ignored.
  • When removing elements, the adapter checks regionTarget.Children.Contains(element) before attempting removal to avoid exceptions.
  • The region is always created as AllActiveRegion, meaning all views are active simultaneously (no deactivation semantics).

Dependencies

Depends on:

  • System.Collections.Specialized (for NotifyCollectionChangedAction)
  • System.Windows (for UIElement)
  • System.Windows.Controls (for StackPanel)
  • Prism.Regions (for RegionAdapterBase<T>, IRegion, IRegionBehaviorFactory, AllActiveRegion)

Depended on by: Not determinable from source alone (likely registered in application bootstrapping or module initialization).

Gotchas

  • The Remove case uses a local variable element assigned from elementLoopVariable in the foreach loop—this appears to be a vestigial pattern (possibly from a VB.NET conversion or older C# version) and is unnecessary in modern C# where foreach loop variables are already scoped per iteration.
  • No handling for Reset or Replace actions means bulk collection changes may not properly synchronize the UI.
  • The null check for region at the start of Adapt() is inconsistent with typical Prism adapter patterns where a null region would indicate a framework error.