-
Notifications
You must be signed in to change notification settings - Fork 48
Custom Region Adapters
Damian edited this page Mar 29, 2024
·
2 revisions
using Avalonia.Controls;
using Prism.Regions;
namespace SuessLabs.PrismAvalonia.RegionAdapters;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class GridRegionAdapter : RegionAdapterBase<Grid>
{
public GridRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
: base(regionBehaviorFactory)
{
}
protected override void Adapt(IRegion region, Grid regionTarget)
{
region.Views.CollectionChanged += (sender, e) =>
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
foreach (Control item in e.NewItems)
{
if (e.NewItems != null)
regionTarget.Children.Add(item);
}
}
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
foreach (Control item in e.OldItems)
{
if (e.OldItems != null)
regionTarget.Children.Remove(item);
}
}
};
}
protected override IRegion CreateRegion() => new SingleActiveRegion() { };
}using Avalonia.Controls;
using Prism.Regions;
namespace SuessLabs.PrismAvalonia.RegionAdapters;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
{
public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
: base(regionBehaviorFactory)
{
}
protected override void Adapt(IRegion region, StackPanel regionTarget)
{
region.Views.CollectionChanged += (sender, e) =>
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
foreach (Control item in e.NewItems)
{
if (e.NewItems != null)
regionTarget.Children.Add(item);
}
}
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
foreach (Control item in e.OldItems)
{
if (e.OldItems != null)
regionTarget.Children.Remove(item);
}
}
};
}
protected override IRegion CreateRegion() => new SingleActiveRegion() { };
}