Binding DocumentPane.ItemsSource to ViewModel

Oct 12, 2010 at 3:27 PM

Hi,

I use AvalonDock and try Bind the ItemSource to my ViewModel like this:

<avalonDock:DockingManager Grid.Row="1" x:Name="DockingManager">
	<avalonDock:ResizingPanel Orientation="Horizontal">
		<avalonDock:ResizingPanel Orientation="Vertical">
			<avalonDock:DocumentPane ItemsControl.ItemsSource="{Binding Path=Documents, Mode=TwoWay}" SelectedItem="{Binding Path=SelectedDocument, Mode=TwoWay}" />
			<avalonDock:DockablePane ItemsControl.ItemsSource="{Binding Path=BottomPanels, Mode=TwoWay}" SelectedItem="{Binding Path=SelectedBottomPanel, Mode=TwoWay}" />
		</avalonDock:ResizingPanel>
		<avalonDock:DockablePane ItemsControl.ItemsSource="{Binding Path=RightPanels, Mode=TwoWay}" SelectedItem="{Binding Path=SelectedRightPanel, Mode=TwoWay}" />
	</avalonDock:ResizingPanel>
</avalonDock:DockingManager>

This works fine as long as I don't want to close one of the Documents. I always get an InvalidOperationException when clicking the [x] to close the document, telling me to use "ItemsControl.ItemsSource" instead of "ItemSource".

When clicking on the Pin-Symbol to pin the panel, I receive a NullReferenceException without any message.

What am I doing wrong trying to bind the ItemsSouces of the DocumentPane and DockablePanes?

The properties of the ViewModel look like this (where DocumentView is inherited from DocumentContent and PanelView from DockableContent):

		public ObservableCollection<DocumentView> Documents
		{
			get { return (ObservableCollection<DocumentView>)GetValue(DocumentsProperty); }
			set { SetValue(DocumentsProperty, value); }
		}


		public ObservableCollection<PanelView> BottomPanels
		{
			get { return (ObservableCollection<PanelView>)GetValue(BottomPanelsProperty); }
			set { SetValue(BottomPanelsProperty, value); }
		}


		public ObservableCollection<PanelView> RightPanels
		{
			get { return (ObservableCollection<PanelView>)GetValue(RightPanelsProperty); }
			set { SetValue(RightPanelsProperty, value); }
		}


		public DocumentView SelectedDocument
		{
			get { return (DocumentView)GetValue(SelectedDocumentProperty); }
			set { SetValue(SelectedDocumentProperty, value); }
		}


		public PanelView SelectedBottomPanel 
		{
			get { return (PanelView)GetValue(SelectedBottomPanelProperty); }
			set { SetValue(SelectedBottomPanelProperty, value); }
		}


		public PanelView SelectedRightPanel
		{
			get { return (PanelView)GetValue(SelectedRightPanelProperty); }
			set { SetValue(SelectedRightPanelProperty, value); }
		}

Thanks, Christian

Nov 2, 2010 at 1:36 PM

Any news ?

I have the same problem when binding ItemsSource from a DockablePane...

Nov 2, 2010 at 4:41 PM

Yeah, kind of... I use the DocumentsSource property of the DockingManager. That works for Documents but not for other panels. So, there's still no solution for ToolBox-like panels. Anyway, this is my XAML:

 

<avalonDock:DockingManager 
  DocumentsSource="{Binding Path=Documents, Mode=TwoWay}"
  ActiveDocument="{Binding Path=SelectedDocument, Mode=TwoWay}">
  <!-- ... -->
</avalonDock:DockingManager>