Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
1. Create a page without apply any control template.
2. Binding this page to a PageModel
3. Change control template for the main view in runtime, like in some button click event.
4. the mainview's binding context become null
Thank you for filing this report! Let me try reproducing this issue with a sample project and I will update the report with my results.
Created attachment 20476 [details]
I believe I was able to reproduce this issue with the sample project I am attaching. In the sample project, I set the BindingContext of the page to a TestViewModel and added a Label with its Text property bound to a property in the view model. When I added a ControlTemplate to the page, the Label Text would disappear.
However, I think this is an expected result as control templates should be using TemplateBinding instead. This means that when you add a control template to the view, the existing bindings in the view should be changed to TemplateBindings so they work properly. As mentioned in the guide linked below, a TemplateBinding's source is set to the parent of the control template, therefore you may not be able to access the properties in the view model unless you map those properties on the parent view as well. A quick sample demonstrating can be check out here: https://www.dropbox.com/s/8i768abgacpi0on/TemplateBinding.zip?dl=0
Hope this helps! If this is not the issue you are experiencing, please re-open this report and attach a sample project that reproduces the issue you are describing. Thanks!