1

我想将 prism 与Fluent.Ribbon. 我的两个 RegionAdapter 之一按预期工作,另一个失败。

protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.Register<RibbonRegionAdapter>();
            containerRegistry.Register<RibbonTabItemRegionAdapter>();
        }


 <Fluent:Ribbon Grid.Row="0" prism:RegionManager.RegionName="RibbonRegion" >
            <Fluent:RibbonTabItem Header="Region">
                <Fluent:RibbonGroupBox Header="Group_B" prism:RegionManager.RegionName="GroupRegion" >
                <Fluent:Button Header="Red"/>
                <Fluent:Button Header="Blue" />

            </Fluent:RibbonGroupBox>
            </Fluent:RibbonTabItem>
        </Fluent:Ribbon>

 public class RibbonTabItemRegionAdapter : RegionAdapterBase<RibbonTabItem>
    {

        public RibbonTabItemRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        protected override void Adapt(IRegion region, RibbonTabItem regionTarget)
        {
            region.Views.CollectionChanged += (sender, args) => ViewsOnCollectionChanged(regionTarget, args);
        }

        private static void ViewsOnCollectionChanged(RibbonTabItem regionTarget, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (var newItem in e.NewItems)
                    {
                        regionTarget.Groups.Add((RibbonGroupBox)newItem);
                    }
                    regionTarget.BringIntoView();
                    break;
                case NotifyCollectionChangedAction.Remove:
                    foreach (var oldItem in e.OldItems)
                    {
                        regionTarget.Groups.Remove((RibbonGroupBox)oldItem);
                    }
                    break;
            }
        }

        protected override IRegion CreateRegion()
        {
            //  return new AllActiveRegion();
            return new Region();
        }
    }

RibbonRegion 按预期工作。GroupRegion 已初始化但未添加到 RegionsCollection。对此有任何想法吗?

4

0 回答 0