Can't RequestNavigate after Closing on PRISM + Unity

6 posts, 1 answers
  1. Jongmin Lee
    Jongmin Lee avatar
    1 posts
    Member since:
    Mar 2010

    Posted 12 Jul 2012 Link to this post

    Hi Telerick,

    I am testing telerik for PRISM + Unity. 
    All of control is beyond my expectation and working great.

    However, I experienced one major issue when using RegionManager.RequestNavigate after closing RadPane.
    When caller navigates with bookId, there is no issue when the book id is new. The new view is created and activated well.
    But I met two issue when the book id exits on list of view.
    First, The existing view is not activated after RegionManager.RequestNavigate 
    Second, I closed the one book view and called RegionManager.RequestNavigate  with the book id. In this time, Not thing happens.
    The old view looks like alive in the view list....

    I am using RadPaneGroupRegionAdapter which comes from your blog
    And I tried to DockingExtension on forum but showing same issues.
    I spend almost two weeks in order solve this issue but I can't get any clue... 

    1. ------------- caller ---------------
    query.Add("BookId", book.Id.ToString());

    RegionManager.RequestNavigate( RegionName.MainContent, new Uri("BookView" + query.ToString(), UriKind.Relative), NavigationComplted);

    2. -------    BookViewModel
    public bool IsNavigationTarget(NavigationContext navigationContext)
    {
    UriQuery query = navigationContext.Parameters;
    int bookId = Convert.ToInt32(query["BookId"]);

    if (this.BookId == bookId)
    return true;

    return false;
    }


    3. --- RegionAdapter comes from your blog

    public class RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup>
        {
            public RadPaneGroupRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
                : base(regionBehaviorFactory)
            {
     
            }
     
            protected override void AttachBehaviors(IRegion region, RadPaneGroup regionTarget)
            {
                base.AttachBehaviors(region, regionTarget);
            }
     
            
     
            protected override void Adapt(IRegion region, RadPaneGroup regionTarget)
            {
                
                region.Views.CollectionChanged += (s, e) =>
                {
                    switch (e.Action)
                    {
                        case NotifyCollectionChangedAction.Add:
                            foreach (var item in e.NewItems.OfType<RadPane>())
                            {
                                regionTarget.Items.Add(item);
                            }
                            break;
                        case NotifyCollectionChangedAction.Remove:
                            foreach (var item in e.OldItems.OfType<RadPane>())
                            {
                                //regionTarget.Items.Remove(item);
                                item.RemoveFromParent();
                            }
                            break;
                        case NotifyCollectionChangedAction.Replace:
                            var oldItems = e.OldItems.OfType<RadPane>();
                            var newItems = e.NewItems.OfType<RadPane>();
                            var newItemsEnumerator = newItems.GetEnumerator();
                            foreach (var 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 (var view in region.Views)
                            {
                                regionTarget.Items.Add(view);
                            }
     
                            break;
                        default:
                            break;
                    }
                };
     
                foreach (var view in region.Views.OfType<RadPane>())
                {
                    regionTarget.Items.Add(view);
                }
            }
     
            protected override IRegion CreateRegion()
            {
                return new AllActiveRegion();
            }
        }
    


    4. -- Docking Extension

       public class DockingExtensions
        {
            public static bool GetRemovePanesWhenClosed(DependencyObject obj)
            {
                return (bool)obj.GetValue(RemovePanesWhenClosedProperty);
            }
     
            public static void SetRemovePanesWhenClosed(DependencyObject obj, bool value)
            {
                obj.SetValue(RemovePanesWhenClosedProperty, value);
            }
     
            public static readonly DependencyProperty RemovePanesWhenClosedProperty =
                DependencyProperty.RegisterAttached("RemovePanesWhenClosed"typeof(bool), typeof(DockingExtensions), new PropertyMetadata(false, OnRemovePanesWhenClosedPropertyChanged));
     
            private static void OnRemovePanesWhenClosedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                var newValue = (bool)e.NewValue;
                var dock = d as RadDocking;
     
                if (dock != null)
                {
                    if (newValue)
                    {
                        dock.PreviewClose += dock_PreviewClose;
                    }
                    else
                    {
                        dock.PreviewClose -= dock_PreviewClose;
                    }
                }
            }
     
            private static void dock_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
            {
                foreach (var pane in e.Panes)
                {
                    DependencyObject o = pane.Parent;
     
     
                    pane.RemoveFromParent();
                    pane.Content = null;
                    pane.Header = null;
                    pane.DataContext = null;
                }
                e.Handled = true;
            }
        }
  2. Answer
    George
    Admin
    George avatar
    1332 posts

    Posted 18 Jul 2012 Link to this post

    Hello,

    When a pane is closed, it's actually hidden so it can be restored much easily. This logic is by design but it can be changed. As long as I understand the given scenario, the problem is that the view(pane) is still alive after closing. In this case I would suggest handling the RadDocking.Close event (not PreviewClose). Move the given code from PreviewClose event handler to the Close event handle and add the following snippet:

    foreach (var pane in e.Panes)
    {
        this.regionManager.Regions["YourRegionName"].Remove(pane);
    }

     
    Please, give it a try and let me know if this helps.

    Greetings,
    George
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Ed James
    Ed James avatar
    9 posts
    Member since:
    Sep 2008

    Posted 29 Oct 2013 Link to this post

    I'm using the RadPaneGroupRegionAdaptor as above, but do not understand the DockingExtensions or how to get them working.

    The problem I have is when a user closes (hides) a tab in the DocumentHost. When a menu item is clicked to re-show the pane it doesn't show.

    The code I'm using is as follows:

    var region = this.regionManager.Regions[RegionNames.DocumentHostRegion];
    var view = this.serviceLocator.GetInstance<AccountManagerView>();
     
    if (region.Views.Contains(view))
    {
         region.Remove(view);
    }
    region.Add(view);
    region.Activate(view);

  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 31 Oct 2013 Link to this post

    Hi,

    We are not sure what could be causing the described issue. As the ItemsSource property is not supported in the current version of the control there may be issues when trying to implement PRISM with RadDocking.

    Currently we working on an example that would demonstrate our vision on how the RadDocking should be used with MVVM and PRISM in its current state. We cannot confirm when this example will be available but you could keep an eye on our online SDK repository here where the example would be uploaded when ready.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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. Rob Conley
    Rob Conley avatar
    47 posts
    Member since:
    Sep 2012

    Posted 06 Nov 2013 Link to this post

    I'm trying to "region.Activate(view);" for the first time and the view is not being activated in the group.
    Any idea when the sample app will be available?
  7. George
    Admin
    George avatar
    1332 posts

    Posted 11 Nov 2013 Link to this post

    Hello Rob,

    Activating view in RadDocking control using PRISM will be shown in the sample as well. It will be available for the Q3 SP1 release in the beginning of the December.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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
UI for WPF is Visual Studio 2017 Ready