Bug 28120 - MasterDetailPage: Referencing XAML DataTemplates in a ListView within a Page set in the Detail property results in a "LoadTemplate should not be null" error
Summary: MasterDetailPage: Referencing XAML DataTemplates in a ListView within a Page ...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-03-17 13:46 UTC by Jeremy Sinclair
Modified: 2015-09-22 10:01 UTC (History)
5 users (show)

Tags: all crash listview xaml
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jeremy Sinclair 2015-03-17 13:46:22 UTC
I have a ContentPage that I use in a project that binds items from a particular ViewModel to a ListView and uses a ViewCell as a DataTemplate (stored within a ResourceDictionary) to display these items. 

I decided to switch to using a MasterDetailPage in order to present a left pane in the application's context, so I made a new page and set the Detail property to new NavigationPage(new BlahblahContentPage()).

When I execute the application, I can consistently make it crash when it attempts to load the ItemTemplate on the ListView. 

I went as far as manually setting the ItemTemplate in the codebehind (lstResults.ItemTemplate = this.Resources["NewsTemplate"] as DataTemplate). When I run lstResults.ItemTemplate.CreateContent(), it crashes with the "LoadTemplate should not be null" error.

Even explicitly setting the DataTemplate within <ListView.ItemTemplate> on the XAML page instead of storing it in the Resources will give the same exact error.

The only thing that works for me is creating the ViewCell and all of my bindings from the codebehind. I created a CreateViewCell method that I pass through to the DataTemplate constructor. This doesn't crash on ItemTemplate.CreateContent();


public MainContent()

                 BindingContext = SimpleIoc.Default.GetInstance<MainModel>();
		 lstResults.ItemTemplate = new DataTemplate(() => { return CreateViewCell(); });


This seems to only cause issues in the context of a MasterDetailPage when using ItemTemplates. If the page is accessed regularly and not from within the Detail property, everything works perfectly. 

I'd prefer being able to use XAML DataTemplates instead of setting everything from the codebehind as it can get crazy. 

Comment 1 Rui Marinho 2015-05-18 12:42:39 UTC
Can you provide a simple project for this particular issue? as i m not being able to reproduce this on my end. 
Comment 2 Rui Marinho 2015-09-22 10:01:48 UTC
Since no feedback was provided, and i wasn't able to reproduce the problem i will be closing this issue. Please reopen if you still see this issue. 

Warms Regards
Xamarin Forms Team