55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.Collections.Specialized;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using Microsoft.Practices.Prism.Regions;
|
|
|
|
namespace DTS.Viewer
|
|
{
|
|
public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
|
|
{
|
|
|
|
public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
|
|
: base(regionBehaviorFactory)
|
|
{
|
|
}
|
|
|
|
protected override void Adapt(IRegion region, StackPanel regionTarget)
|
|
{
|
|
if (region == null) return;
|
|
|
|
region.Views.CollectionChanged += (sender, e) =>
|
|
{
|
|
switch (e.Action)
|
|
{
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
foreach (UIElement element in e.NewItems)
|
|
{
|
|
regionTarget.Children.Add(element);
|
|
}
|
|
break;
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
foreach (UIElement elementLoopVariable in e.OldItems)
|
|
{
|
|
var element = elementLoopVariable;
|
|
|
|
if (regionTarget.Children.Contains(element))
|
|
{
|
|
regionTarget.Children.Remove(element);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
};
|
|
}
|
|
|
|
protected override IRegion CreateRegion()
|
|
{
|
|
return new AllActiveRegion();
|
|
}
|
|
}
|
|
|
|
}
|