RadDocking + MEF + Prism 4 + RegisterViewWithRegion = Element already has a logical parent

2 posts, 1 answers
  1. Peter
    Peter avatar
    1 posts
    Member since:
    Nov 2010

    Posted 13 Aug 2011 Link to this post

    Hi,

    I have been stuck with this issue for a few days now and I need to move on. I am attempting to convince our company to use Telerik + Prism 4 for a new project we are undertaking, however I cannot even show them how to add a document to a RadDock when they click a button in the Ribbon Bar.

    All of my problems center around our friend, the RadPaneGroupRegionAdapter and the implementation provided by Telerik. It simply does not work. I can register the views (documents) successfully on startup of the application, however as soon as my command attempts to execute the following code:
    m_RegionManager.RegisterViewWithRegion(WpfPrism.Infrastructure.Helpers.RegionNameHelper.Document, typeof(Views.Search)); 

    All is lost and I get the following error:

    System.InvalidOperationException was unhandled by user code
    Message=Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.
    Source=PresentationFramework
    StackTrace:
    at MS.Internal.Controls.InnerItemCollectionView.AssertPristineModelChild(Object item)
    at MS.Internal.Controls.InnerItemCollectionView.Add(Object item)
    at System.Windows.Controls.ItemCollection.Add(Object newItem)
    at Telerik.Windows.Controls.RadSplitContainer.PrepareContainerForItemOverride(DependencyObject element, Object item) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\Docking\Docking\Docking\RadSplitContainer.cs:line 689
    at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
    at System.Windows.Controls.Panel.GenerateChildren()
    at System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
    at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
    at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
    at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
    at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
    at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
    at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
    at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
    at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
    at System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
    at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
    at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
    at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
    at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
    at MS.Internal.Data.EnumerableCollectionView.LoadSnapshot(IEnumerable source)
    at MS.Internal.Data.EnumerableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
    at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
    at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
    at Microsoft.Practices.Prism.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\ViewsCollection.cs:line 124
    at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyReset() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\ViewsCollection.cs:line 129
    at Microsoft.Practices.Prism.Regions.ViewsCollection.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\ViewsCollection.cs:line 255
    at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
    at System.Collections.ObjectModel.Collection`1.Add(T item)
    at Microsoft.Practices.Prism.Regions.Region.InnerAdd(Object view, String viewName, IRegionManager scopedRegionManager) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\Region.cs:line 380
    at Microsoft.Practices.Prism.Regions.Region.Add(Object view, String viewName, Boolean createRegionManagerScope) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\Region.cs:line 275
    at Microsoft.Practices.Prism.Regions.Region.Add(Object view) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\Region.cs:line 246
    at Microsoft.Practices.Prism.Regions.Behaviors.AutoPopulateRegionBehavior.AddViewIntoRegion(Object viewToAdd) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\Behaviors\AutoPopulateRegionBehavior.cs:line 84
    at Microsoft.Practices.Prism.Regions.Behaviors.AutoPopulateRegionBehavior.OnViewRegistered(Object sender, ViewRegisteredEventArgs e) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Regions\Behaviors\AutoPopulateRegionBehavior.cs:line 109
     
    Here is a link to where the solution can be found WpfPrism
  2. Answer
    George
    Admin
    George avatar
    1332 posts

    Posted 16 Aug 2011 Link to this post

    Hi Peter,

     
    We took some time to investigate the problem. It seems that in the ShellView where the RadDocking control is defined, the RadSplitContainer is set as a region, but in the BootStrapper.ConfigureRegionAdapterMappings() method the mappings are registered for RadPaneGroup, not for the RadSplitContainer. If you set the pane group as region, no exception will be thrown:

    <telerik:RadDocking.DocumentHost>
                    <telerik:RadSplitContainer>
                        <telerik:RadPaneGroup prism:RegionManager.RegionName="DocumentRegion" />
                    </telerik:RadSplitContainer>
                </telerik:RadDocking.DocumentHost>

    I hope this helps.

    All the best,
    George
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top