--- source_files: - Common/DTS.CommonCore/RegionManager/RegionAdapters/StackPanelRegionAdapter.cs - Common/DTS.CommonCore/RegionManager/RegionAdapters/ViewerStackPanelRegionAdapter.cs generated_at: "2026-04-17T16:24:44.545909+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "bc7a539f71ee8ad5" --- # RegionAdapters ### Purpose This module provides Prism region adapters for `StackPanel` controls, enabling WPF `StackPanel` elements to participate in Prism's region navigation and view composition system. It contains two adapters—`StackPanelRegionAdapter` and `ViewerStackPanelRegionAdapter`—that synchronize region views with the panel's `Children` collection, allowing dynamic addition and removal of UI elements through region management. ### Public Interface **`StackPanelRegionAdapter`** - Constructor: `StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)` — Initializes the adapter with the specified behavior factory. - Inherits from `RegionAdapterBase` **`ViewerStackPanelRegionAdapter`** - Constructor: `ViewerStackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)` — Initializes the adapter with the specified behavior factory. - Inherits from `RegionAdapterBase` ### Invariants - Both adapters create an `AllActiveRegion` via `CreateRegion()`, meaning all views in the region are considered active at all times. - The `Adapt` method returns immediately if `region` is null; no exception is thrown. - Only `Add` and `Remove` collection change actions are handled; `Replace`, `Move`, and `Reset` actions are ignored. ### Dependencies - **Depends on:** `System.Windows` (for `UIElement`), `System.Windows.Controls` (for `StackPanel`), `System.Collections.Specialized` (for `NotifyCollectionChangedAction`), `Microsoft.Practices.Prism.Regions` (for `RegionAdapterBase`, `IRegion`, `IRegionBehaviorFactory`, `AllActiveRegion`) - **Dependents:** Unknown from source alone; likely registered during application bootstrapping or module initialization. ### Gotchas - **Code duplication:** `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 modules. - **Memory leak potential:** The `CollectionChanged` event handler is attached but never detached. If the region or adapter lifetime exceeds the `StackPanel` lifetime, this could prevent garbage collection. - **Unhandled collection actions:** `NotifyCollectionChangedAction.Replace`, `Move`, and `Reset` are not handled in the switch statement. A `Reset` action (e.g., from `Clear()`) would not clear the `StackPanel.Children`. ---