Files
FATrace/FATrace.WPLApp/RegionAdapter/SfNavigationDrawerRegionAdapter.cs
2025-10-29 11:42:58 +08:00

94 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Prism.Regions;
using Syncfusion.UI.Xaml.NavigationDrawer;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace FATrace.WPLApp.RegionAdapter
{
public class SfNavigationDrawerRegionAdapter : RegionAdapterBase<SfNavigationDrawer>
{
public SfNavigationDrawerRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
: base(regionBehaviorFactory)
{
}
protected override void Adapt(IRegion region, SfNavigationDrawer regionTarget)
{
{
//////Old Version
//if (regionTarget == null)
// throw new ArgumentNullException(nameof(regionTarget));
//bool contentIsSet = regionTarget.ContentView != null;
//contentIsSet = contentIsSet || null != BindingOperations.GetBinding(regionTarget, ContentControl.ContentProperty);
//if (contentIsSet)
// throw new InvalidOperationException("ContentControlHasContentException");
//region.ActiveViews.CollectionChanged += delegate
//{
// regionTarget.ContentView = region.ActiveViews.FirstOrDefault();
//};
//region.Views.CollectionChanged +=
//(sender, e) =>
//{
// if (e.Action == NotifyCollectionChangedAction.Add && region.ActiveViews.Count() == 0)
// {
// region.Activate(e.NewItems[0]);
// }
//};
}
//New Version
if (region == null)
{
throw new ArgumentNullException(nameof(region));
}
if (regionTarget == null)
{
throw new ArgumentNullException(nameof(regionTarget));
}
// 处理活动视图变化 - 这是界面切换的关键
region.ActiveViews.CollectionChanged += (s, e) =>
{
// 当有视图被激活时将其设置为ContentView
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null && e.NewItems.Count > 0)
{
regionTarget.ContentView = e.NewItems[0] as FrameworkElement;
}
};
// 处理视图集合变化
region.Views.CollectionChanged += (s, e) =>
{
// 当添加新视图且没有活动视图时,自动激活它
if (e.Action == NotifyCollectionChangedAction.Add &&
e.NewItems != null &&
e.NewItems.Count > 0 &&
region.ActiveViews.Count() == 0)
{
region.Activate(e.NewItems[0]);
}
};
}
protected override IRegion CreateRegion()
{
return new SingleActiveRegion();
//return new Region();
}
}
}