RegionAdapter for Fluent.Ribbon

273 Views Asked by At

I would like to use prism toghter with Fluent.Ribbon. One of my two RegionAdapters works as expected, the other one fails.

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();
        }
    }

The RibbonRegion works as expected. The GroupRegion is initialized but not added to the RegionsCollection. Any idea About this?

0

There are 0 best solutions below