用于Fluent.Ribbon的RegionAdapter

时间:2019-03-30 21:29:00

标签: prism fluent-ribbon

我想与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中。 有任何想法吗?

0 个答案:

没有答案