The StackPanel immediately catches your eye when you think of stacking items vertically. Unfortunately, Prism does not support StackPanel as a region out of the box. Fortunately, you can create a RegionAdapter to fix this problem.
Public Class StackPanelRegionAdapter Inherits RegionAdapterBase(Of StackPanel) Public Sub New(ByVal behaviorFactory As IRegionBehaviorFactory) MyBase.New(behaviorFactory) End Sub Protected Overrides Sub Adapt(ByVal region As IRegion, ByVal regionTarget As StackPanel) AddHandler region.Views.CollectionChanged, Sub(sender As Object, e As NotifyCollectionChangedEventArgs) If e.Action = NotifyCollectionChangedAction.Add Then For Each element As FrameworkElement In e.NewItems regionTarget.Children.Add(element) Next Else If e.Action = NotifyCollectionChangedAction.Remove Then For Each element In e.OldItems If regionTarget.Children.Contains(element) Then regionTarget.Children.Remove(element) End If Next End If End Sub End Sub Protected Overrides Function CreateRegion() As Microsoft.Practices.Prism.Regions.IRegion Return New AllActiveRegion End Function End Class
From there, you just need to add the mapping to OverrideRegionAdapterMappings Override in your boot file.
Protected Overrides Function ConfigureRegionAdapterMappings() As Microsoft.Practices.Prism.Regions.RegionAdapterMappings Dim mappings = MyBase.ConfigureRegionAdapterMappings() mappings.RegisterMapping(GetType(Grid), Container.Resolve(Of PrismExtensions.GridRegionAdapter)) mappings.RegisterMapping(GetType(StackPanel), Container.Resolve(Of PrismExtensions.StackPanelRegionAdapter)) Return mappings End Function
Edit: Found a John Papa link from which I originally received the code. (In C #, if this is what you are using) Fill in the area of ββmy prism, please
source share