我正在尝试在 Syncfusion 导航抽屉(https://help.syncfusion.com/wpf/navigation-drawer/getting-started)上实现一个 RegionAdapter。
我看到它使用变量(对象)ContentView 来显示视图,所以我写了这个:
public class SfNavigationDrawerRegionAdapter : RegionAdapterBase<SfNavigationDrawer>
{
public SfNavigationDrawerRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
{
}
protected override void Adapt(IRegion region, SfNavigationDrawer regionTarget)
{
if (region == null)
{
throw new ArgumentNullException(nameof(region));
}
if (regionTarget == null)
{
throw new ArgumentNullException(nameof(regionTarget));
}
region.Views.CollectionChanged += (s, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (FrameworkElement view in e.NewItems) {
regionTarget.ContentView = view;
}
}
// in events Remove is never called but Reset is called after a Add action
};
}
protected override IRegion CreateRegion()
{
return new SingleActiveRegion();
}
}
此代码段执行以下行为:(https://i.imgur.com/kHVFfQh.mp4)当我单击已加载的视图时,它不会更改 ContentView 中的视图(不调用 CollectionChanged)。
预期的行为是它应该显示视图。
我怎么能做到这一点?
感谢您的阅读!