Operation is not valid while ItemsSource is in use

Oct 24, 2008 at 11:12 PM
i use avalondock with composite wpf  applicazion.
when i set a region to a dockablepanel and i try to move a windows obtain:

Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
in this method:

public FlyoutDockablePane(DockableContent content)

 

 

...

_referencedPane.Items.RemoveAt(_arrayIndexPreviousPane);

....

can you help me ?
thanks.
Oct 27, 2008 at 8:21 AM
Can you please specify better how to reproduce this? and can you also post the complete exception trace log?  Ado
Oct 27, 2008 at 10:43 AM

Hi Ado,

i have build an application with CompositeWPF and your avalondock.

This is a piece of shell

<ad:DockablePane ad:ResizingPanel.ResizeWidth="100" ad:ResizingPanel.ResizeHeight="200" Name="DockablePane2" cal:RegionManager.RegionName="RightRegion">
</
ad:DockablePane>

 

 

 

note cal:RegionManager.RegionName="RightRegion" this bind your library with compositeWPF


in IModule of compositeWPF i have wrote

Dim
mainRegion As IRegion = Me.regionManager.Regions("RightRegion")
mainRegion.Add(mcash,
"Cash")

 

where mcash has a view like this

 

<

 

ad:DockableContent Width="Auto" x:Class="CashDispenserView" Title="Cash Dispenser"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:aw="clr-namespace:Assergs.Windows;assembly=Assergs.Windows"
xmlns:awc="clr-namespace:Assergs.Windows.Controls;assembly=Assergs.Windows"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
xmlns:local="clr-namespace:FrameWork">

 

 

 

<ad:DockableContent.Icon>

 

 

 

<Image Width="16" Height="16" Source="Q:\SVILUPPO\DotNet\AvalonDock\AvalonDock\AvalonDockTest\Images\demo.png"/>
</ad:DockableContent.Icon>
<awc:RibbonPanel Visibility="Visible" Height="200" Header="Disponibilità" Name="DispPanel" VerticalContentAlignment="Top">
<Grid VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition />

 

 

 

<ColumnDefinition />

 

 

 

</Grid.ColumnDefinitions>

 

 

 

<Grid.RowDefinitions>

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

<RowDefinition />

 

 

 

</Grid.RowDefinitions>

 

 

 

<Label Grid.Column="0" Grid.Row="0">500€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="1">200€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="2">100€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="3">50€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="4">20€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="5">10€:</Label >

 

 

 

<Label Grid.Column="0" Grid.Row="6">5€:</Label >

 

 

 

<Button Name="btnConnect" Grid.Row="6" Grid.Column="1" Content="Save" ></Button>

 

 

 

</Grid>

 

 

 

</awc:RibbonPanel>

 

</

 

ad:DockableContent>

 

The compositeWPF add the view corectly but when i move/hide the panel obtain:

 

System.InvalidOperationException was unhandled

Message="Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."

Source="PresentationFramework"

StackTrace:

at System.Windows.Controls.ItemCollection.CheckIsUsingInnerView()

at System.Windows.Controls.ItemCollection.RemoveAt(Int32 removeIndex)

at AvalonDock.FlyoutDockablePane..ctor(DockableContent content) in Q:\SVILUPPO\DotNet\AvalonDock\AvalonDock\AvalonDock\FlyoutDockablePane.cs:line 66

at AvalonDock.FlyoutPaneWindow..ctor(DockableContent content) in Q:\SVILUPPO\DotNet\AvalonDock\AvalonDock\AvalonDock\FlyoutPaneWindow.cs:line 125

at AvalonDock.DockingManager.ShowFlyoutWindow(DockableContent content) in Q:\SVILUPPO\DotNet\AvalonDock\AvalonDock\AvalonDock\DockingManager.cs:line 1935

at AvalonDock.DockablePaneAnchorTab.OnMouseMove(MouseEventArgs e) in Q:\SVILUPPO\DotNet\AvalonDock\AvalonDock\AvalonDock\DockablePaneAnchorTab.cs:line 128

at System.Windows.UIElement.OnMouseMoveThunk(Object sender, MouseEventArgs e)

at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)

at System.Windows.Input.InputManager.ProcessStagingArea()

at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)

at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.Run()

at System.Windows.Application.RunDispatcher(Object ignore)

at System.Windows.Application.RunInternal(Window window)

at System.Windows.Application.Run(Window window)

at System.Windows.Application.Run()

at FrameWork.Application.Main() in Q:\SVILUPPO\DotNet\EasyBank\lib\FrameWork\obj\Debug\Application.g.vb:line 51

InnerException:

 

 

 

Oct 27, 2008 at 12:36 PM
Hi, I'm afraid that AvalonDock is not compatible with WPF composite UI application pattern. The main problem is that UIComposition is itself a layout manager like AvalonDock so the first can't manage the region itemscontrol while the second is referencing it.
Sorry, Ado
Oct 27, 2008 at 1:46 PM
Thanks Ado,
I try to write a custom regionmanager.


Feb 10, 2009 at 9:41 PM
If anyone does figure out an adapter to make these 2 great frameworks play together with regards to itemscontrol, please post.
Feb 13, 2009 at 1:41 PM
Edited May 26, 2009 at 3:13 PM

I'm using both AvalonDock and Composite WPF without problems through custom region and slightly modified bootstrapper.

See my blog post about it.

Feb 15, 2009 at 8:12 AM
Great ! I will check out your blog post.
Another thing, I want to enable drag&drop onto the DockableContent. This works fine as long as the content is visible, but doesn't work when it is minimized.
Also, I would like to handle the drop event in my view (in the module), not in the Window1 codebehind file. I guess the event must be dispatched to the module somehow.
Feb 16, 2009 at 11:58 AM
I have copied your source code from the blog post, but get error because "Name" is an unknown object.
Also, I have another question: in which project should I place DockREgion.cs ?
Feb 16, 2009 at 12:14 PM
I also get a whole load of other compile errors.
You need to show the complete code (maybe an example solution), if you want people to try this out.
Feb 17, 2009 at 8:39 AM
OK, I've added usings for AvalonDockRegion, hope that'll help. Maybe I'll make a working sample project in the future, but blogspot is not a good place for posting attachments. My idea was to check for positive response, then publish a more polished version of this article on codeproject.

Name is a member of AvalonDock's DockableContent class. Can't see what's wrong with that.

As to which project goes the region class, it's completely up to you to decide. You may make your own project named "CalToAvalonDockProxy" or "EntLibExtensions" and place AvalonDockRegion and CustomRegionsBootstrapper there.
Mar 5, 2009 at 4:31 PM
Guys,

I am desperate to see these two libraries working together.
I want to build an application using CAL.
I want the UI to take advantage of the floating/docking functionality in Avalon Dock.

adospace....

"Hi, I'm afraid that AvalonDock is not compatible with WPF composite UI application pattern. The main problem is that UIComposition is itself a layout manager like AvalonDock so the first can't manage the region itemscontrol while the second is referencing it."

Can you elaborate on this some more, what exactly would it take to fix this?

As I'm sure you know, a key component of CAL is the Unity IoC container.
Which could be used to create a singleton object.
Could it not be possible to create a single object of type 'items control' and inject a reference to that object into both the DockingManager and the RegionManager? or am I completly off track?


cvolpato....

Did you get anywhere with your custom region manager?


aw....

In your CustomRegionsBootstrapper you have a method called ConfigureRegions and in that method you call this.ConfigureDefaultRegionBehaviors();
Well the unity bootstrapper class doesn't have a ConfigureDefaultRegionBehaviors() method - can you tell me what's supposed to go in there?

I see a couple of people have shown interest in your solution. Please post some sample code that works.

Any help, guidance or advice would be really appreciated (and I'm more than happy to share any results I may come up with!)

Many thanks.


MQCA.

Mar 10, 2009 at 3:24 PM
Edited May 26, 2009 at 3:15 PM

I've finally added sources to my blog post about CAL\docking integration - sorry, I was too busy to make a sample project earlier.

MQCA: I used code from PRISM 2 alpha, not from CAL 1.0. PRISM 2 bootstrapper do contain ConfigureDefaultRegionBehaviors().

Mar 11, 2009 at 10:27 AM
AW - Many thanks, really appreciate you taking the time to share a sample project. I have the code now and it works, now I just need to tweak it to fit my exact scenario!

Thanks again :o)

MQCA.
Jul 7, 2010 at 10:59 AM

Sorry to dig up an old thread....the Region Adapters from Composite WPF Contrib work fine with Prism2, Unity 2.0 and VS2010 (.NET 3.5 - not my decision).

GE