This is a migrated thread and some comments may be shown as answers.

Can't RequestNavigate after Closing on PRISM + Unity

5 Answers 311 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Jongmin Lee
Top achievements
Rank 1
Jongmin Lee asked on 12 Jul 2012, 07:15 PM
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;
        }
    }

5 Answers, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 18 Jul 2012, 10:05 AM
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.

0
Ed James
Top achievements
Rank 2
answered on 29 Oct 2013, 08:38 AM
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);

0
Vladi
Telerik team
answered on 31 Oct 2013, 09:44 AM
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 >>
0
Rob Conley
Top achievements
Rank 1
answered on 07 Nov 2013, 01:26 AM
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?
0
George
Telerik team
answered on 11 Nov 2013, 03:30 PM
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 >>
Tags
Docking
Asked by
Jongmin Lee
Top achievements
Rank 1
Answers by
George
Telerik team
Ed James
Top achievements
Rank 2
Vladi
Telerik team
Rob Conley
Top achievements
Rank 1
Share this question
or