Bug 58148 - Xamarin.Forms Previewer Bindings not evaluated when Page is in a separate project without App.xaml, works fine at run time and when located in the main app project.
Summary: Xamarin.Forms Previewer Bindings not evaluated when Page is in a separate pro...
Status: RESOLVED NORESPONSE
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Xamarin.Forms Previewer ()
Version: 4.5.0 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-13 22:38 UTC by Jim Albert
Modified: 2017-08-17 07:04 UTC (History)
3 users (show)

Tags:
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 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 NORESPONSE

Description Jim Albert 2017-07-13 22:38:21 UTC
I'm working on a project where the Xamarin.Forms code is split between different projects:
 * A .Net Standard "UI" project with shared Converters, Extensions, etc.
 * A .Net Standard "Platform" project with shared Pages, Controls, etc.
 * A .Net Standard "App" project with App.xaml and app-specific Pages, Controls, logic, etc.
 * Platform-Specific (Android, UWP, iOS) applications that reference all of the above.

I recently needed to move one of my "App" pages down into the "Platform" level of the stack.  The page uses a design-time ViewModel declared in the XAML, and before the move everything was displayed and all of the bindings were evaluated correctly, such that I could update the design-time ViewModel directly in the XAML and see the results instantly.  After the move, even though the page continues to work correctly at run-time,  the Xamarin.Forms Previewer is no longer evaluating any of the bindings on my page.  For example:
 * I have IsVisible bindings to display different Labels in different cases, now all of the Labels are displayed all of the time on top of each other.
 * I have a ListView that was bound to an ItemsSource in my ViewModel, now the ListView is empty.

The Previewer does not show any warnings or errors in either case, and there's nothing in the logs (the Visual Studio Output window logs, is there another log specifically for the Xamarin.Forms previewer?).

I've ruled out a .Net Standard issue since the Previewer worked find when the page was in the "App" .Net Standard project.

The only guess I have is that the preview worked when the page was in the project with the App.xaml, and my design-time helper code uses Application.Current to determine when to apply the design-time ViewModel.  Is the previewer behavior different when there's no App.xaml in the project for the page being previewed?
Comment 1 Jim Albert 2017-07-14 14:18:41 UTC
The behavior around the issue seems to be as I expected: I modified my design-time check logic slightly to make it so that when Application.Current is null, it will use the design-time data.

Although I still have no way to confirm it (can't debug the Previewer, nothing in the logs), this seems to be the behavior:
 * When you're previewing a page in a project that has an App.xaml, Application.Current will be an instance of that, but any lifecycle events won't have been called.
 * When you're previewing a page in a project that doesn't have an App.xaml, Application.Current will be null.

This likely also has implications for App ResourceDictionary items (I was using a separate ResourceDictionary for styling, that I needed to pull in manually for the previewer to work).

This issue can be closed, but is there any workflow for updating the Xamarin.Forms documentation - specifically this page?
https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-previewer/
Comment 2 Prashant [MSFT] 2017-07-17 07:11:19 UTC
@Jim,

I believe this works as designed, attach a reproduction to the bug by starting with a clean project and adding just the code necessary to demonstrate the issue. It will help us to investigate the issue.

> This issue can be closed, but is there any workflow for updating the 
> Xamarin.Forms documentation - specifically this page?

What changes would you like to see in the documentation?
Comment 3 Prashant [MSFT] 2017-08-17 07:04:25 UTC
Because we have not received a reply to our request for more information, we are marking this issue as RESOLVED→NORESPONSE. If you are still encountering this issue on the latest Visual Studio 2017 Preview version 15.3, please don’t hesitate to reopen the ticket with the requested information. 

Thanks!