45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using Prism.Regions;
|
|
|
|
namespace FlexitimeTaskbarUtility.Extensions
|
|
{
|
|
public class ContextMenuRegionAdapter:RegionAdapterBase<ContextMenu>
|
|
{
|
|
public ContextMenuRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
|
|
{
|
|
}
|
|
|
|
protected override void Adapt(IRegion region, ContextMenu regionTarget)
|
|
{
|
|
region.Views.CollectionChanged += (s, e) =>
|
|
{
|
|
if (e.Action == NotifyCollectionChangedAction.Add)
|
|
{
|
|
foreach (var item in e.NewItems)
|
|
{
|
|
regionTarget.Items.Add(item);
|
|
}
|
|
}
|
|
else if (e.Action == NotifyCollectionChangedAction.Remove)
|
|
{
|
|
foreach (var oldItem in e.OldItems)
|
|
{
|
|
regionTarget.Items.Remove(oldItem);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
protected override IRegion CreateRegion()
|
|
{
|
|
return new Region();
|
|
}
|
|
}
|
|
}
|