Bug 21699 - WebView does not propagate its BindingContext to its Source
Summary: WebView does not propagate its BindingContext to its Source
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: Macintosh Mac OS
: Normal minor
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-07-30 11:26 UTC by Adam Kemp
Modified: 2016-04-11 12:54 UTC (History)
13 users (show)

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

Test case (2.53 MB, application/zip)
2014-07-30 11:26 UTC, Adam Kemp

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 Adam Kemp 2014-07-30 11:26:56 UTC
Created attachment 7534 [details]
Test case

I have a WebView defined in XAML like this:

    <HtmlWebViewSource Html="{Binding SomeProperty}" />

This doesn't work because the BindingContext of the WebView does not get inherited by the HtmlWebViewSource.

My current workaround is to override OnBindingContextChanged to manually set the BindingContext of the WebView's Source:

        protected override void OnBindingContextChanged()

            _webView.Source.BindingContext = BindingContext;

I shouldn't have to do that.

To reproduce the issue see the attached project. If you run the app you will see a blank screen. You should see "Hello, World!". To test the workaround find the OnBindingContextChanged() method in MyPage and uncomment the commented out line.
Comment 1 Udham Singh 2014-08-13 14:41:31 UTC
I have checked this issue and observed the same behaviour mentioned in bug description. To reproduce this issue I have followed the instructions provided in bug description.

Screencast : http://www.screencast.com/t/XdBoIKvPg

Environment Info : 

=== Xamarin Studio ===

Version 5.2.1 (build 1)
Installation UUID: 952292e8-1484-4c56-b664-6ff701bef591
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		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)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 606f31a
Build date: 2014-08-01 15:27:48-0400

=== Build Information ===

Release ID: 502010001
Git revision: d06832ce9807d6be24aca225457e8b37c7669f6f
Build date: 2014-08-07 12:10:47-04
Xamarin addins: 1de032531be4cecf2f39dbee3b87aac78204058c

=== Operating System ===

Mac OS X 10.9.3
Darwin Xamarin76s-Mac-mini.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 2 Michael Rumpler 2015-09-24 06:40:36 UTC
Also when the BindingContext or the property bound to Html or BaseUrl changes, the WebView does not reload.

I tested this only on iOS in XF
Comment 3 Sascha Schwegelbauer 2015-12-02 15:06:25 UTC
A WebView created in XAML with it's Source set to a HtmlWebViewSource.Html bound to a ViewModel-Property also does not update itself but shows only a white area.
On Windows Phone, it simply crashes.
This happens on XF 2.0
It's no minor bug anymore, because finding it out took me 2 hours and it's well known at Xamarin for at least one year!
Comment 4 wislon 2015-12-14 09:33:41 UTC
Confirmed that this is still an issue with XF 2.0 (latest stable versions of everything). 

Luckily the temporary workaround still works. But really, it's been nearly 18 MONTHS since this was reported AND confirmed?
Comment 5 Benjamin Krämer 2016-03-12 19:47:44 UTC
The problem with HtmlWebViewSource.Html in combination with ViewModel seems to be, that th WebView looses the Source reference after some time. The HtmlWebViewSource is updated if this patch from above is applied, but since the WebView has now a reference in the source field to UrlWebViewSource. The only workaround I found is to register on the PropertyChanged event of my ModelView and to set the source back when the property was changed...

The stacktrace of the moment looks like this (propertyName is Source):
MyProject.FixedWebView.OnPropertyChanging(string propertyName) in
Xamarin.Forms.BindableObject.SetValueActual(Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject.BindablePropertyContext context, Xamarin.Forms.UrlWebViewSource value, bool currentlyApplying, Xamarin.Forms.BindableObject.SetValueFlags attributes, bool silent) in
Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, Xamarin.Forms.UrlWebViewSource value, Xamarin.Forms.BindableObject.SetValueFlags attributes, Xamarin.Forms.BindableObject.SetValuePrivateFlags privateAttributes) in
Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, Xamarin.Forms.UrlWebViewSource value, Xamarin.Forms.BindableObject.SetValueFlags attributes) in
Xamarin.Forms.Element.Xamarin.Forms.IElementController.SetValueFromRenderer(Xamarin.Forms.BindableProperty property, Xamarin.Forms.UrlWebViewSource value) in
Xamarin.Forms.Platform.iOS.WebViewRenderer.CustomWebViewDelegate.LoadingFinished(MyProject.iOS.BaseUrlWebViewRenderer webView) in
UIKit.UIApplication.UIApplicationMain() in
UIKit.UIApplication.Main( args, principal, delegate)
UIKit.UIApplication.Main( args, principalClassName, delegateClassName)
MyProject.iOS.Application.Main(string[] args)

It is more than a minor bug and still in there in the latest XF 2.1!
Comment 6 Jason Smith [MSFT] 2016-03-18 09:53:31 UTC
Should be fixed in 2.2.0-pre1
Comment 7 Parmendra Kumar 2016-04-11 12:54:01 UTC
I have checked this issue with Xamarin.Forms 2.2.0-pre2 and observed that its working fine.

Hence closing this issue.