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

System.InvalidOperationException when docking

3 Answers 99 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Maciej Czerwiakowski
Top achievements
Rank 1
Maciej Czerwiakowski asked on 15 Dec 2009, 12:52 PM
I'm working on application using Prism and yours Q3 WPF controls. Unfortunately when I'm trying to dock control in another dock region the InvalidOperationException is thrown. Exception message says I should use ItemsControl.ItemsSource instead of ItemsSource and I really don`t known how to solve this.

Below you'll find my region adapter class, dockable view class and docking container declaration in main window

Region adapter
namespace LTD.Desktop.Common 
    public class RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup> 
    { 
        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 (var item in e.NewItems.OfType<RadPane>()) 
                        { 
                            regionTarget.AddItem(item, Telerik.Windows.Controls.Docking.DockPosition.Center); 
                        } 
                        break
                    case NotifyCollectionChangedAction.Remove: 
                        foreach (var item in e.OldItems.OfType<RadPane>()) 
                        { 
                            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()); 
                        break
                    default
                        break
                } 
            }; 
 
            foreach (var view in region.Views.OfType<RadPane>()) 
            { 
                regionTarget.Items.Add(view); 
            } 
        } 
 
        protected override IRegion CreateRegion() 
        { 
            return new AllActiveRegion(); 
        } 
    } 

Dockable view
namespace LTD.Examples.Modularity.Views 
    /// <summary> 
    /// Interaction logic for ExampleView.xaml 
    /// </summary> 
    public partial class ExampleView : RadDocumentPane 
    { 
        public ExampleView() 
        { 
            InitializeComponent(); 
        } 
    } 

<telerik:RadDocumentPane x:Class="LTD.Examples.Modularity.Views.ExampleView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    Header="Example panel"/> 
 

ExampleView class in design time also generate en error: Could not create an instance of type 'RadDocumentPane'

Views container:
<!-- Workspaces container --> 
        <telerik:RadDocking Name="Workspaces" DockPanel.Dock="Bottom" cal:RegionManager.RegionName="Workspaces"
            <telerik:RadDocking.DocumentHost> 
                <telerik:RadSplitContainer> 
                    <telerik:RadPaneGroup cal:RegionManager.RegionName="MainRegion" /> 
                </telerik:RadSplitContainer> 
            </telerik:RadDocking.DocumentHost> 
        </telerik:RadDocking> 

It's critical for me, so I'll be appreciate for any help.

Regards,
MC.

3 Answers, 1 is accepted

Sort by
0
Maciej Czerwiakowski
Top achievements
Rank 1
answered on 15 Dec 2009, 01:32 PM
I`ve solved problem by changing docking declaration to:

<!-- Workspaces container --> 
<telerik:RadDocking> 
    <telerik:RadDocking.DocumentHost> 
        <telerik:RadSplitContainer> 
            <telerik:RadPaneGroup cal:RegionManager.RegionName="MainRegion" /> 
        </telerik:RadSplitContainer> 
    </telerik:RadDocking.DocumentHost> 
</telerik:RadDocking> 

and changing base class of dockable view form RadDocumantPane to RadPane.

Regards,
MC
0
Kaloyan
Telerik team
answered on 17 Dec 2009, 09:00 AM
Hi Maciej Czerwiakowski,

Actually this is the right way for achieving this scenario. Also yon can grab some interesting ideas form this blog post.

Kind regards,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Maciej Czerwiakowski
Top achievements
Rank 1
answered on 17 Dec 2009, 12:49 PM
HI Kaloyan !

Frankly speaking I took region adapter form MIroslav`s post on yours team blog :)
As I wrote in previous post problem was solved by changing docking declarations, so thanks for confirming my solution!

Regards,
MC.
Tags
Docking
Asked by
Maciej Czerwiakowski
Top achievements
Rank 1
Answers by
Maciej Czerwiakowski
Top achievements
Rank 1
Kaloyan
Telerik team
Share this question
or