Bug 45727 - DataTemplate with x:Reference throws error when DataTemplate is in App.xaml
Summary: DataTemplate with x:Reference throws error when DataTemplate is in App.xaml
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-20 10:29 UTC by Andrei.N
Modified: 2017-01-24 15:07 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app (187.95 KB, application/x-zip-compressed)
2016-10-20 10:29 UTC, Andrei.N
Details


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:
Status:
RESOLVED ANSWERED

Description Andrei.N 2016-10-20 10:29:15 UTC
Created attachment 18131 [details]
Sample app

A DataTemplate with a x:Reference to a control throws exception when it's placed in App.xaml instead of the Page where the control exists:

System.Exception: Can't resolve name on Element

See MainPage.xaml, MainPage.xaml.cs and App.xaml in my sample, these are the only places where I added code.
Comment 1 Andrei.N 2016-10-20 10:38:16 UTC
This is preventing sharing DataTemplate's across Pages.
Comment 2 Andrei.N 2016-10-20 10:40:35 UTC
I don't see why would this work when DataTemplate is in a Page but not in App.xaml.
Comment 3 Stephane Delcroix 2017-01-24 15:07:12 UTC
"References an instance that is declared elsewhere in XAML markup" (from https://msdn.microsoft.com/en-us/library/ee795380(v=vs.110).aspx)

the scope fo x:Reference is roughly the xaml file in which it is used.

you probably can use a Binding to achieve your goal