The DataTemple of my RadPane are lost when the RadPane goes from being docked to floating. I am using the RadDocking control with MVVM thus I am using the DockingPaneFactory class. So far I have the following XAML in my MainWindow.xaml file.
<
Window
… >
<
Window.Resources
>
<
DataTemplate
DataType=“{x:Type ViewModelA}”>
<
TextBlock
Text=”ViewModelA” />
</
DataTemplate
>
<
DataTemplate
DataType=“{x:Type ViewModelB}”>
<
TextBlock
Text=”ViewModelB” />
</
DataTemplate
>
</
Window.Resources
>
</
Window
>
The XAML above defines two DataTemplates for my two View Models called ViewModelA and ViewModelB. Next I have my RadDocking XAML that defines three RadSplitContainers and the DockingPanesFactory.
<
telerik:RadDocking
PanesSource=”{Binding Panes}”>
<
telerik:RadSplitContainer
InitialPosition=”DockedLeft”>
<
telerik:RadPaneGroup
x:Name=”LeftPaneGroup” />
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition=”DockedRight”>
<
telerik:RadPaneGroup
x:Name=”RightPaneGroup” />
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition=”DockedBottom”>
<
telerik:RadPaneGroup
x:Name=”BottomPaneGroup” />
</
telerik:RadSplitContainer
>
<
telerik:RadDocking.DockingPanesFactory
>
<
local:MyDockingPanesFactory
/>
</
telerik:RadDocking.DockingPanesFactory
>
</
telerik:RadDocking
>
Now I have my DockingPanesFactoryClass.
public class MyDockingPanesFactory : DockingPanesFactory {
protected override void AddPane(…) {
. . . .
}
protected override RadPane CreatePaneForItem(object item) {
if (item is DockPaneViewModel) {
return new RadPane() {
Header = ((DockPaneViewModel)item).Header,
Tag = ((DockPaneViewModel)item).InitialLocation,
DataContext = item,
Content = item
};
} else {
throw new ArgumentException(“Invalid Type”);
}
}
}
The above code sets the Header, Tag, DataContext, and Context of the new RadPane based on property of the ViewModel which inherits from a specific DockPaneViewModel. The key here is that the Content of the RadPane is set to the ViewModel so that the DataTemplate defined in the MainWindow.xaml can be discovered using its DataType.
Lastly, in my MainWindowViewModel (which is the DataContext for the MainWindow.xaml), I define the Panes collection for the binding of the PaneSource property in the RadDocking control.
public class MainWindowViewModel : ViewModelBase {
public ObservableCollection<
DockPaneViewModel
> Panes { get; set; }
public MainWindowViewModel() {
Panes = new ObservableCollection<
DockPaneViewModel
>() {
new ViewModelA(),
new ViewModelB()
};
}
}
When this application is run everything looks as expected and the RadPanes are docked in the correct location. In one of the RadPanes I see the text “ViewModelA” and in the other I see “ViewModelB” so I know the DataTemples are being applied. Now when I pull one of the RadPanes off and make it floating its DataContext seems to be lost and it simply shows the class name in the RadPane. Docking the RadPane back into the RadDocking control does not restore its DataTemplate.
Why do the DataTemples of my RadPanes seem to get removed when I move the RadPane from being docked to being floating?