Bug 43685 - Bindings in ContentView lost when ControlTemplate is changed at runtime.
Summary: Bindings in ContentView lost when ControlTemplate is changed at runtime.
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 43706 ()
Depends on:
Blocks:
 
Reported: 2016-08-23 20:18 UTC by Jon Goldberger [MSFT]
Modified: 2017-06-21 08:35 UTC (History)
8 users (show)

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


Attachments
test Project (76.89 KB, application/zip)
2016-08-23 20:18 UTC, Jon Goldberger [MSFT]
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 FIXED

Description Jon Goldberger [MSFT] 2016-08-23 20:18:48 UTC
Created attachment 17186 [details]
test Project

## Description

Any bindings for a control that are in a ContentView that is being presented by a ControlTemplate are lost when the ControlTemplate is changed at runtime. Same behavior on iOS and Android. The attached test project shows that a binding for a control outside of the ContentView still works after the ControlTemplate is changed, but that a binding inside the ContentView is lost. After going over the docs for Template Bindings [1] the only thing that is not crystal clear is whether the controls in the ContentView need to use TemplateBindings. I would think not because of this note:
"However, note that using a TemplateBinding outside of a ControlTemplate is not supported."

So this leads me to believe there is a bug here. 

[1] https://developer.xamarin.com/guides/xamarin-forms/templates/control-templates/template-binding/

## Steps to reproduce

1. Open the attached test project.

2. Deploy to an Android or iOS device/sim

3. Note that the ListView with the color items is in the ContentView, while the label is outside of the ContentView. ContentView has a Silver background. 

4. Click the Toggle Template button

Expected result: the ListView in the ContentView will still be seen.

Actual result: The ListView in the ContentView disappears because the binding for ItemsSource appears to be lost.

## Regression status

Not a regression, could reproduce in all versions of Forms since ControlTemplate was introduced in XF 2.1. This issue is present in 2.3.2.118-pre1 as well. 

## Environment

=== Xamarin Studio Enterprise ===

Version 6.0.2 (build 73)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Runtime:
	Mono 4.4.2 (mono-4.4.0-branch-c7sr1/f72fe45) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404020011

=== Xamarin.Profiler ===

Version: 0.33.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.Mac ===

Version: 2.8.2.22 (Visual Studio Enterprise)

=== Xamarin.Android ===

Version: 6.1.2.21 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: 9.8.2.22 (Visual Studio Enterprise)
Hash: f37444a
Branch: cycle7-sr1
Build date: 2016-07-28 12:17:02-0400

=== Xamarin Inspector ===

Version: 0.8.0.0
Hash: dc081aa
Branch: master
Build date: Tue Apr 26 23:07:44 UTC 2016

=== Build Information ===

Release ID: 600020073
Git revision: a6f7a24a9723a2d4f5d33c176615b0d44703ab5b
Build date: 2016-07-26 13:36:15-04
Xamarin addins: f5acb37866a0141bc5ddbe95118f18dae4014568
Build lane: monodevelop-lion-cycle7-sr1

=== Operating System ===

Mac OS X 10.11.6
Darwin Jons-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.8.0.0
Comment 2 adrianknight89 2016-10-12 03:33:59 UTC
Referencing https://bugzilla.xamarin.com/show_bug.cgi?id=43706
Comment 3 Stephane Delcroix 2017-06-13 13:51:10 UTC
*** Bug 43706 has been marked as a duplicate of this bug. ***
Comment 4 Stephane Delcroix 2017-06-16 20:00:44 UTC
see https://github.com/xamarin/Xamarin.Forms/pull/998