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

DataContext is NULL with DockingPanesFactory

3 Answers 156 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Ashley
Top achievements
Rank 2
Ashley asked on 30 Mar 2015, 03:14 PM
Hello

I have dug around but found no answer to this. It seems when my new pane is added to the DocumentHost its DataContext is always null and not inherited. 

I was thinking there is some way around this with the DockingPanesFactory but I couldn't find it.

WPF Inspector says that the DataContext is completely fine up until it reaches ContentElement.

Is there a way to get the ContentElement to inherit the DataContext?

3 Answers, 1 is accepted

Sort by
0
Ashley
Top achievements
Rank 2
answered on 30 Mar 2015, 03:20 PM
Sorry I should clear up this question slightly:

I bind my RadDocking panes source:

PanesSource="{Binding RecordsVMM.RecordViewModels}"

This is an observable collection, which I want each RadDocumentPane to be bound to each individual item. To achieve this I do the following:

Declare a custom Pane Factory that Docks with "RecordContainer"

<telerik:RadDocking.DockingPanesFactory>
<record:RecordViewManagerPaneFactory/>
</telerik:RadDocking.DockingPanesFactory>

Then, I use a template selector so based on the TYPE inside PanesSource, I display things differently.

<telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer>
<telerik:RadPaneGroup x:Name="RecordContainer" DropDownDisplayMode="Visible" ContentTemplateSelector="{StaticResource RecordTemplateSelector}"/>
</telerik:RadSplitContainer>
</telerik:RadDocking.DocumentHost>


Unfortunately, once my template is selected. The DataContext is NULL, so its useless!
0
Ashley
Top achievements
Rank 2
answered on 31 Mar 2015, 08:00 AM
Spent some time writing a simple app last night which describes this very problem.

Its not entirely clear in the documentation but hopefully this helps somebody in the future:

If you are writing a CustomDockingPanes factory its designed so that you can determine what type of RadPane or RadDocumentPane to instantiate _based on your own ViewModel_

For example, if you use RadDocumentPane in conjunction with a DockingPanesFactory the function CreatePaneForItem WILL NOT GET CALLED because it has already made the assumption that the Pane type is going to be RadDocumentPane - this will then not allow you to pass on the DataContext to it. It just ends up being null.

In short - if you are using DockingPanesFactory it feels like you should never really have a PaneSource which contains a list of RadDocuments because it removes the point of the Factory (other than deciding where to dock it).



Hope this makes sense, maybe you can clear this up in your documentation :)
0
Nasko
Telerik team
answered on 01 Apr 2015, 03:10 PM
Hi Ashley,

We are glad that you managed to achieve the desired functionality and behavior. Indeed when a collection of RadPanes/RadDocumentPanes is passed to the PanesSource of the Docking control the CreatePaneForItem method from the DockingPanesFactory is not called. The main idea of the method is to create RadPane from an item passed from the collection - if panes are passed to the method its functionality becomes meaningless. We will consider to update our documentation with that information.

If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Docking
Asked by
Ashley
Top achievements
Rank 2
Answers by
Ashley
Top achievements
Rank 2
Nasko
Telerik team
Share this question
or