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

RadPanes lose their DataTemplate when it moves from being docked to floating

2 Answers 224 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 10 Jul 2015, 03:12 PM

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?

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 14 Jul 2015, 09:03 AM
Hi Eric,

When a Pane goes floating it is placed in another window that is not in the same visual tree as the Docking control. So, if the DataTemplates are placed in the MainWindow.Resources (that seems to be case in your scenario based on the provided code - snippets and description) they wont' be applied for the floating Panes (they are in another Windows). Please, define the DataTemplates in the App.xaml file, so they could be applied for all the Panes as expected when they become floating and are placed in another window.

Please, give a try to the proposed above approach and let us know if it worked for you.

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Eric
Top achievements
Rank 1
answered on 14 Jul 2015, 02:46 PM
Yup that worked perfectly. I was going to eventually move the DataTemplate(s) to the App.xaml but when I was testing I just kept them in the Windows.Resources. Thanks for the reply.
Tags
Docking
Asked by
Eric
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Eric
Top achievements
Rank 1
Share this question
or