【发布时间】:2018-10-06 20:01:06
【问题描述】:
使用 Microsoft Advertising AdControl 的 Xamarin Forms 项目。打开页面时控件工作正常,但是当页面在其顶部的页面的 PopAsync 之后再次显示页面时,AdControl 为空白,之后保持空白。
我发现了一个似乎关于同一主题的老问题here,但我无法使用答案和 cmets。
当带有 AdControl 的页面在其顶部的页面的 PopAsync 之后重新出现时,e.NewElement 为 null 并且 e.OldElement 具有 AdControlView(我在 PCL 中的自定义视图)。
UWP 渲染器:
public class AdViewRenderer : ViewRenderer<AdControlView, UWPAdView>
{
protected override void OnElementChanged(ElementChangedEventArgs<AdControlView> e)
{
base.OnElementChanged(e);
if (null == Control && e.NewElement != null)
{
UWPAdView ad = new UWPAdView();
SetNativeControl(ad);
}
}
}
UWP 项目中的 AdControl 用户控件:
<UserControl
x:Class="Sample.UWP.Helpers.UWPAdView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:aduwp="using:Microsoft.Advertising.WinRT.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
<Grid>
<aduwp:AdControl
Width="640"
Height="100"
HorizontalAlignment="Stretch"
AdUnitId="myadunitid"
ApplicationId="myappid"
AutoRefreshIntervalInSeconds="30"
ErrorOccurred="AdControl_ErrorOccurred"
IsAutoRefreshEnabled="True" />
</Grid>
</UserControl>
是否有人在 Xamarin Forms UWP 生产应用中使用 AdControl?
【问题讨论】: