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

Docking problem with DataTemplates

3 Answers 93 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Martin Robins
Top achievements
Rank 1
Martin Robins asked on 25 Nov 2019, 11:16 AM

Given the following (simplified) class...

    class SearchResultsViewModel
    {
        public IList Results { get; }
        public SearchCriteria Criteria { get; }
    }

And the following (also simplified) WPF DataTemplate's...

    <DataTemplate DataType="{x:Type viewModels:SearchCriteria}">
        <StackPanel>
            <!-- Various controls used to display/edit  the SearchCriteria class properties-->
        </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="{x:Type viewModels:SearchResultsViewModel}">
        <telerik:RadDocking>
            <telerik:RadDocking.DocumentHost>
                <telerik:RadSplitContainer>
                    <telerik:RadPaneGroup>
                        <telerik:RadDocumentPane Visibility="Collapsed"
                                                 CanUserClose="False">
                            <telerik:RadBusyIndicator BusyContent="{Binding Path=BusyContent}"
                                                      IsBusy="{Binding Path=IsBusy, Mode=OneWay}">
                                <telerik:RadGridView ItemsSource="{Binding Path=Results}" />
                            </telerik:RadBusyIndicator>
                        </telerik:RadDocumentPane>
                    </telerik:RadPaneGroup>
                </telerik:RadSplitContainer>
            </telerik:RadDocking.DocumentHost>
            <telerik:RadSplitContainer InitialPosition="DockedLeft">
                <telerik:RadPaneGroup IsContentPreserved="True">
                    <telerik:RadPane CanUserClose="False"
                                     CanFloat="False"
                                     DataContext="{Binding Path=Criteria}"
                                     Header="Search Criteria"
                                     IsPinned="False">
                        <ContentPresenter Content="{Binding}" />
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking>
    </DataTemplate>

When I display the SearchResultsViewModel (using a ContentPresenter), I see - as expected - a list of the results along with a tab on the left of the page with the header "Search Criteria"; however when I then click on the tab to open the associated panel and view the properties of the "SearchCriteria" class I see a repeat of the whole "SearchResultsViewModel" DataTemplate instead of just the properties of the "SearchCriteria" using its own DataTemplate. This then repeats recursively so each time I click on the tab it opens yet another copy.

I have also tried setting "Content={Binding Path=Criteria}" on the "ContentPresenter" instead of setting the "DataContext={Binding Path=Criteria}" on the "RadPane" but this makes no difference.

I use the DataTemplate for the "SearchCriteria" elsewhere within the application and it is called upon based upon the DataType being shown rather than any specific reference to the specific template so I do not want to have to give the template an "x:Key" and then reference it specifically here either but then I do not expect to have to do this as it works elsewhere.

What am I doinng wrong to make the ContentPresenter within the second DataTemplate show the "SearchCriteriaViewModel" DataTemplate instead of the "SearchCriteria" DataTemplate?

3 Answers, 1 is accepted

Sort by
0
Martin Robins
Top achievements
Rank 1
answered on 25 Nov 2019, 01:30 PM
A couple of images to better demonstrate the issue that I am seeing. The same applies if I drop the "DataContext=" from the RadPane and instead set "Content="{Binding Path=Criteria}"" on the ContentPresenter.
0
Martin Robins
Top achievements
Rank 1
answered on 25 Nov 2019, 02:25 PM

See also the discussion of this problem on Stack Overflow...

https://stackoverflow.com/questions/59030732/wpf-contentpresenter-within-datatemplate-shows-incorrect-datatemplate-content

0
Martin Ivanov
Telerik team
answered on 28 Nov 2019, 09:44 AM

Hello Martin,

I've tested the code snippets but I wasn't able to replace the issue. Can you check the attached project and let me know if I am missing anything?

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Docking
Asked by
Martin Robins
Top achievements
Rank 1
Answers by
Martin Robins
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or