简体   繁体   中英

Workaround now broken for: UWP AdControl blank after PopAsync in Xamarin Forms

"Xamarin Forms project using the Microsoft Advertising AdControl. The control works fine when a page is opened, but when a page is shown again after a PopAsync of a page on top of it, the AdControl is blank, and stays blank after that."

This is an old problem , also 4+ years ago here , but the workaround, which (worked in 4.1 and earlier) is now broken in forms 4.2 & 4.3, was to call InitializeComponent() again in OnAppearing. It's broken now because duplicate names cause a runtime exception.

Other than getting Microsoft to fix the bug, what's the correct way to get the adControl to work after a popasync?

I try to use Xamarin.forms latest version 4.3.0.908675to test, and I have error message:

An element with the same key already exists in NameScope

But I use the xamarin.forms version 4.0.0.709238, it works fine.

Workaround:

Install Xamarin.Forms version 4.0.0.709238 instead the latest version.

I will report this bug for MS, you can also report this bug in Github, so MS will see it to try to fix.

From Xamarin.forms on github:

"if you want this to work, set the Namescope of your view to null before invoking InitializeComponent a second time." they added... "but mostly: don't call InitializeComponent() twice"

It be a more complete answer if anyone can elaborate and provide an example of setting the Namescope of the view to null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM