In some situations, only blank page is rendered when the application starts. After the window is resized by the user, all the content suddenly appears. I have prepared a simplified version of my project:
There is a page with a SearchBar, CollectionView and a Button. When the app is started, only blank page is displayed. When I resize the window, all the content (SearchBar, CollectionView and a Button) becomes visible.
This is even more complicated as this bug is present about 90% of times, but sometimes when I run the app, the content is visible immediately (usually when I delete bin and obj folders manually). When I rerun the app, the bug is there.
Another complication is that depending on Xamarin.Forms version, the behavior seems to be sometimes different depending on if you use Debug or Release versions! I have found the bug when just before uploading my app to Microsoft Store. I have used only Debug version during development. Before uploading the final version I wanted to try also the Release version just to be sure. And I have found out that it is not working. In my case, version 4.6.0.726 worked correctly in Debug but not in the Release mode. Upgrading to 4.6.0.847 made things even worse and the bug was there in both Debug and Release modes. However, I am not able to reproduce this difference in by repro solution.
Just creating the repro solution took me a few hours because I started with my app and removed one thing by another and tested if the bug is still there (both in debug and release; and UWP release build is ridiculously slow). I needed to make sure that the bug is not caused by some other Nuget.
This bug might be connected to the Issue #10862. However, there is no need to click and navigate in this case (compared to the situation mentioned in #10862). So it can be a different problem.
The content (SearchBar, CollectionView and a Button) is visible right after the start. Also the behavior should be deterministic and it should be the same for Debug and Release versions.
The content is hidden (most of the times) until the window is resized.
When the app is started, nothing is there:
When I resize the window, all content become visible:
Just to note here, things not showing up or sized correctly until a window resize, etc seems to be a consistent theme in the UWP backend especially related to Labels or Entries. I suspect there are still some underlying issues that we are all trying to bandaid, but I haven't been able to track it down.
Below are some open and closed issues and PRs on related items.
Verified - I got the blank screen on the first try.
I'm on a single monitor, so at the very least we know this isn't another instance of a UWP second monitor bug.
I wonder if this is an issue with the Device display metrics not being initialized. We have had at least one bug previously where uninitialized display size values caused CollectionView problems, and a window resize will force the display size values to update.
We too can confirm this issue and see it intermittently on UWP in both debug and release builds.
@hartez I didn't have much success searching for info about the Device Display Metrics. Is that a collection view thing or UWP? Just looking for a pointer, I was thinking about looking into the entry/editor text not showing until resize as it's starting to be a real pain!
@bmacombe For UWP, that stuff would be in the WindowsDeviceInfo class. It's a long shot, but I know that a while back we had a CollectionView bug where it didn't display at all in Shell; the culprit turned out to be that the DeviceInfo stuff on Android wasn't being initialized properly on startup.
Which Entry/Editor thing were you looking at? I know there's one where if you set a height, it doesn't display the text (or vice versa, can't remember right now) - is that what you're investigating?
@hartez Here are a couple
issues
I just get the feeling there has to be something common to all these problems and my gut thinks it's in the FormsTextBox or the control template. My PR just used a hack already in place in the editor to try to fix the entry also. It seems to work on the height issue, but not the text showing. The entry/editor getting focus or a window resize seems to do the trick. I've wondered if it's a timing issue on when the UWP text property is being set or something like that.
Thinking about starting with what is in PR #8536 that @WayaFlyfeather was working on, I think it fixed the text not showing, but when combined with my PR broke other behavior.
my gut thinks it's in the FormsTextBox or the control template
You're probably right. I spent some time looking at this one evening, and the issue seemed to be related to the ScrollViewer in the template. But I didn't have time to dig any deeper than that.
If you are desperate to get this working, here is my "workaround" - hide the CollectionView on UWP and use a ListView instead. It will not look nice and it is probably not efficient but the page is displayed at least.
<CollectionView
ItemTemplate="{StaticResource ItemsDataTemplate}"
ItemsSource="{Binding Items}"
IsVisible="{OnPlatform Default=True, UWP=False}" />
<ListView
ItemTemplate="{StaticResource ItemsDataTemplateUwp}"
ItemsSource="{Binding Items}"
IsVisible="{OnPlatform Default=False, UWP=True}" />
@hartez Do you have any recommendations on how we can assist with this issue? We can confirm the behaviour in the repro project.
Looking at WindowsDeviceInfo
:
DisplayInformation.GetForCurrentView()
valid at the time when the CollectionView
is drawn? Is there any _difference_ in the params before and after a window resize?Thanks Emil, I’d be really interested in seeing your research into this problem.
Sent from my iPhone
On 8/07/2020, at 1:34 AM, Emil Alipiev notifications@github.com wrote:

I have this issue when i load the data in OnAppearing, if i use Constructor or Init method to load data, everything is fine. is your problem related to that? I found the root cause and I will send a PR for that one also.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
I wonder if #11351 is a possible fix?
@hartez Do you have any recommendations on how we can assist with this issue? We can confirm the behaviour in the repro project.
Looking at
WindowsDeviceInfo
:
- There is a todo comment there, has this been addressed?
- What is the context when this class is initialized?
- I'm guessing this doesn't blow up, but is the information returned by
DisplayInformation.GetForCurrentView()
valid at the time when theCollectionView
is drawn? Is there any _difference_ in the params before and after a window resize?
@velocitysystems I wonder if something like this what is meant by that todo. Doesn't do anything to help with this issue though unfortunately
I wonder if #11351 is a possible fix?
Doesn't fix 😞
Just an observation, while stepping through VisualElementPackager. All the controls were visible on the initial load when I ran out of code to step through. Maybe there is a timing issue in play here?
Just hitting a breakpoint in VisualElementPackage.SetupVisualElement is enough to get the controls to be visible.
Other observation...on the initial load, only the renderers for the labels inside the collection view templates are having their GetDesiredSizecalled. After you resize the window, everything gets GetDesiredSize called.
It seems setting the ItemsSource of the CollectionView during the hosting page's OnAppearing might be causing this. Just commenting that out makes everything show on the first load (minus the items)
If they are set in the ctor, they load fine.
I wonder if having the collection view render new items while the page is starting to be displayed is causing an issue with the layout process
Even adding a minor delay in OnAppearing causes them to load fine.
@bmacombe @hartez @samhouts Hi XF Team, This is on our critical list. We cannot ship a product that displays a blank page half the time.
@pwillies I'm just a contributor that got sucked into this issue out of curiosity while working on a PR for another UWP issue. But #11394 PR is ready for review by the team when they can get to it.
If you really need a temp workaround, adding a delay before setting the ItemSource of maybe 10ms or so seemed to work in most cases. 2-3ms was normally plenty, but my machines are pretty fast so a longer one would be best.
Is this going to be included in the nugget of Xamarin forms?
We cant wait until MAUI is released.
Most helpful comment
@bmacombe @hartez @samhouts Hi XF Team, This is on our critical list. We cannot ship a product that displays a blank page half the time.