Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Prism V5 MahApps Flyout Adapter Region

$
0
0
Hi!

I am trying to use MahApps metro with my wpf prism application but i have issues creating custom region adapter for Flyouts... I have created custom adapter for StackPanel which works fine if it is loaded in grid of the shell but MahApps metro uses this for loading flyouts
<Controls:MetroWindow.Flyouts>
        <Controls:FlyoutsControl x:Name="flyoutsControl">
            <Controls:Flyout Header="Accented"
                                Position="Right"
                                Theme="Accent" >
                <StackPanel cal:RegionManager.RegionName="StackPanelRegion" />
            </Controls:Flyout>
</Controls:MetroWindow.Flyouts>
for the testing purposes i use code behind and i call the flyout like this
private void ShowAccent(object sender, RoutedEventArgs e)
        {
            this.ToggleFlyout(0);      
        }
and i call the view that i want to navigate to in the flyout like this
private void Button_Click(object sender, EventArgs e)
        {
            IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

            if (regionManager == null) throw new ArgumentNullException("regionManager");

            regionManager.RequestNavigate(RegionNames.StackPanelRegion,
                               new Uri("Test3", UriKind.Relative));
        }
I tried loading the wiew on ,odule load but than i get null region exception. If i load it with button click and put break point, there are no errors but also no StackPanelRegion in regionManager...

this is my custom adapter
public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
    {
        public StackPanelRegionAdapter(IRegionBehaviorFactory factory)
            : base(factory)
        {
        }
        protected override void Adapt(IRegion region, StackPanel regionTarget)
        {
            region.ActiveViews.CollectionChanged += (s, e) =>
            {
                if(e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach(FrameworkElement element in e.NewItems)
                    {
                        regionTarget.Children.Add(element);
                    }
                }
            };
        }

        protected override IRegion CreateRegion()
        {
            return new AllActiveRegion();
        }
    }
and my bootstrapper mapping
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
            mappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
            return mappings;
        }
I know adapter works because if i put it inside of the shell grid, region is registered and view is displayed...

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>