Issue with Prism and RadDock when adding panes at runtime

6 posts, 0 answers
  1. Dave K
    Dave K avatar
    5 posts
    Member since:
    May 2009

    Posted 04 Apr 2013 Link to this post

    Currently my application is built using Prism and MEF. I have a Shell with Prism Regions set on each RadGroup within the main docking control as shown here:
    <telerik:RadDocking Grid.Row="2" Width="Auto" Height="Auto">
         <telerik:RadDocking.DocumentHost>
             <telerik:RadSplitContainer>
                 <telerik:RadPaneGroup x:Name="ShellRegionDockCentral" prism:RegionManager.RegionName="ShellRegionDockCentral"/>
             </telerik:RadSplitContainer>
         </telerik:RadDocking.DocumentHost>
     
         <telerik:RadSplitContainer InitialPosition="DockedLeft">
             <telerik:RadPaneGroup x:Name="ShellRegionDockLeft" prism:RegionManager.RegionName="ShellRegionDockLeft"/>
         </telerik:RadSplitContainer>
     
         <telerik:RadSplitContainer InitialPosition="DockedRight">
             <telerik:RadPaneGroup x:Name="ShellRegionDockRight" prism:RegionManager.RegionName="ShellRegionDockRight"/>
         </telerik:RadSplitContainer>
     
         <telerik:RadSplitContainer InitialPosition="DockedTop">
             <telerik:RadPaneGroup x:Name="ShellRegionDockTop" prism:RegionManager.RegionName="ShellRegionDockTop"/>
         </telerik:RadSplitContainer>
     
         <telerik:RadSplitContainer InitialPosition="DockedBottom">
             <telerik:RadPaneGroup x:Name="ShellRegionDockBottom" prism:RegionManager.RegionName="ShellRegionDockBottom"/>
         </telerik:RadSplitContainer>
     </telerik:RadDocking>
     
    I have utilized the "RadPaneGroupRegionAdapter" (see code below) that I got from one of the forum posts and everything works perfect when the modules are initially loaded and the default views are injected into their respective Regions.
     
    [Export(typeof(RadPaneGroupRegionAdapter))]
        public class RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup>
        {       
            [ImportingConstructor]
            public RadPaneGroupRegionAdapter ( IRegionBehaviorFactory regionBehaviorFactory ) : base ( regionBehaviorFactory )
            {
            }
             
            protected override void Adapt ( IRegion region, RadPaneGroup regionTarget )
            {
                region.Views.CollectionChanged += ( s, e ) =>
                {
                    switch ( e.Action )
                    {
                        case NotifyCollectionChangedAction.Add: foreach ( RadPane item in e.NewItems.OfType<RadPane> () )
                        {
                            regionTarget.Items.Add ( item );
                        } break;
                        case NotifyCollectionChangedAction.Remove: foreach ( RadPane item in e.OldItems.OfType<RadPane> () )
                        {
                            item.RemoveFromParent ();
                        } break;
                        case NotifyCollectionChangedAction.Replace:
                            IEnumerable<RadPane> oldItems = e.OldItems.OfType<RadPane> ();
                            IEnumerable<RadPane> newItems = e.NewItems.OfType<RadPane> ();
                            IEnumerator<RadPane> newItemsEnumerator = newItems.GetEnumerator ();
                            foreach ( RadPane oldItem in oldItems )
                            {
                                var parent = oldItem.Parent as ItemsControl;
                                if ( parent != null && parent.Items.Contains ( oldItem ) )
                                {
                                    parent.Items [parent.Items.IndexOf ( oldItem )] = newItemsEnumerator.Current;
                                    if ( !newItemsEnumerator.MoveNext () )
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    oldItem.RemoveFromParent ();
                                    regionTarget.Items.Add ( newItemsEnumerator.Current );
                                }
                            }
                            break;
                        case NotifyCollectionChangedAction.Reset:
                            regionTarget
                                        .EnumeratePanes ()
                                        .ToList ()
                                        .ForEach ( p => p.RemoveFromParent () );
                            foreach ( object view in region.Views )
                            {
                                regionTarget.Items.Add ( view );
                            }
                            break;
                    }
                };
                 
                foreach ( RadPane view in region.Views.OfType<RadPane> () )
                {
                    regionTarget.Items.Add ( view );
                }
            }
             
            protected override IRegion CreateRegion ()
            {
                return new AllActiveRegion () ;
            }
        }
    }

    Module code to load views into region on startup...
    [ModuleExport(typeof(IPTMembersModule), InitializationMode = InitializationMode.OnDemand)]
        public class PTMembersModule: IPTMembersModule
        {
            private IRegionManager _regionManager;
     
            public void Initialize()
            {
                this._regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
                this._regionManager.RegisterViewWithRegion("ShellRegionDockCentral", typeof(MembersListingView));
                this._regionManager.RegisterViewWithRegion("ShellRegionDockRight", typeof(MemberDetailsView));
            }
        }

     

    As mentioned, everything works just perfect and each view is loaded correctly and displayed as it should. The problem that occurs though is when I attempt to inject another View into one of the Regions (either already existing or one that doesn't have anything displayed in it). I have a button on the Shell that when gets clicked, gets handled by a DelegateCommand on the ViewModel side and the code within that is as follows:

    IRegion region = this.RegionManager.Regions["ShellRegionDockLeft"];
                var view = this.ServiceLocator.GetInstance(typeof(MemberDetailsView2));
                if (region.Views.Contains(view))
                {
                    region.Remove(view);
                }
                region.Add(view, "MemberDetailsView2");
                region.Activate(view);

    Seems ok, but when the code is run during runtime the view gets displayed and then closes almost immediately. This happens no matter which region I try and load the view. The other thing I notice is that the code within the "RadPaneGroupRegionAdapter" doesn't get fired when adding a View this way, is this normal?

    Either way I'm sure there is something odd going on and I've been banging my head off a wall to try and figure out why when loading these new views after the application is running just display quickly then close. I have even tried doing the same thing using the "RequestNavigate" method within the region manager, but still the same thing.

    Any help on this?
  2. Dave K
    Dave K avatar
    5 posts
    Member since:
    May 2009

    Posted 05 Apr 2013 Link to this post

    Ignore this issue, Silly oversight on my part but seems that the issue revolved around the code which was used to create a new view once a module was loaded. I needed to switch the code over to the module that contained the view(s) i needed to load, Once I moved the code over to the respective module, everything worked OK!
  3. DevCraft banner
  4. Ed James
    Ed James avatar
    9 posts
    Member since:
    Sep 2008

    Posted 29 Oct 2013 Link to this post

    Hi Dave,

    I've been trying to find a working region adaptor for RadDock. I've tried the code you posted above, but it doesn't handle tab names within the pane. Do you have a full working code sample?

    Thanks
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 31 Oct 2013 Link to this post

    Hi,

    We do not have a complete example of PRISM with RadDocking that we can share with you.

    Currently we are working on such example and hope to have it available as soon as possible. When it is available it will be uploaded to our online SDK repository at GitHub. You can find the repository here and download it as a zip file via this link.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Ed James
    Ed James avatar
    9 posts
    Member since:
    Sep 2008

    Posted 06 Nov 2013 Link to this post

    Hi Vladi,

    Thanks - that would be fantastic. Please let me know when it's available.
  7. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 07 Nov 2013 Link to this post

    Hello,

    I recommend you to regularly check our online SDK repository at GitHub where the example would be uploaded when available.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner