C# 调整Microsoft广告的大小

C# 调整Microsoft广告的大小,c#,uwp,ads,C#,Uwp,Ads,嗨,我在我的UWP应用程序中使用微软的广告,我希望广告在应用程序运行后重新调整大小,但无法使其工作。 我知道广告控件必须在有效大小的任意一个上(如上所述),因此我编写了以下代码来调整广告的大小: private void panel_SizeChanged(object sender, SizeChangedEventArgs e) { if (e.NewSize.Width >= 728) { ad.Width = 728; ad.Heig

嗨,我在我的UWP应用程序中使用微软的广告,我希望广告在应用程序运行后重新调整大小,但无法使其工作。 我知道广告控件必须在有效大小的任意一个上(如上所述),因此我编写了以下代码来调整广告的大小:

private void panel_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if (e.NewSize.Width >= 728)
    {
        ad.Width = 728;
        ad.Height = 90;
    }
    else if (e.NewSize.Width >= 640)
    {
        ad.Width = 640;
        ad.Height = 100;
    }
    else if (e.NewSize.Width >= 480)
    {
        ad.Width = 480;
        ad.Height = 80;
    }
    else if (e.NewSize.Width >= 320)
    {
        ad.Width = 320;
        ad.Height = 50;
    }
    else if (e.NewSize.Width >= 300)
    {
        ad.Width = 300;
        ad.Height = 50;
    }
}
这使得控件相应地调整大小,但控件内的广告看起来很糟糕。我添加了广告刷新();但这并没有改变任何事情


有人知道该怎么办吗?

我也遇到过你同样的问题。 不幸的是,广告每30秒加载一次,你不能在30秒内刷新一次。 这就是调用Refresh()方法失败的原因。 我使用了一种变通方法,希望它能帮助您。 我已经用与广告大小(和位置)相同的堆叠面板“覆盖”了广告。当我不得不改变广告大小时,我已经展示了这个面板。 在刷新广告时(你可以通过回调函数ADREFRESHID截获),我已经隐藏了封面

<StackPanel x:Name="AdsCover" Width="300" Height="50" Visibility="Visible"
                   Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.ZIndex="12" Background="WhiteSmoke">
            <Border x:Name="AdsBorder" BorderBrush="{x:Null}" Height="50">
                <TextBlock x:Name="AdsLoading" Text="Ads Loading..." HorizontalAlignment="Center" FontStyle="Italic" FontFamily="Calibri" FontSize="24"
                       TextAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </StackPanel>
        <UI:AdControl x:Name="adsMS" 
                ApplicationId="3f83fe91-d6be-434d-a0ae-7351c5a997f1"
                AdUnitId="10865270"
                HorizontalAlignment="Left"
                Height="50"
                VerticalAlignment="Bottom"
                Width="300"
                Grid.Column="0" Grid.ColumnSpan="3"
                Canvas.ZIndex="10"
                ErrorOccurred="OnAdErrorOccurred"
                AdRefreshed="OnAdRefreshed"/>
在OnAddressFreshed()回调中,可以隐藏面板

// Called when the Ad is refreshed.
void DirectXPage::OnAdRefreshed(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    // If the Ad is hidden by the cover panel, I will make it visible again.
    if (AdsCover->Visibility == Windows::UI::Xaml::Visibility::Visible)
        AdsCover->SetValue(VisibilityProperty, Windows::UI::Xaml::Visibility::Collapsed);
}

我也遇到过你同样的问题。 不幸的是,广告每30秒加载一次,你不能在30秒内刷新一次。 这就是调用Refresh()方法失败的原因。 我使用了一种变通方法,希望它能帮助您。 我已经用与广告大小(和位置)相同的堆叠面板“覆盖”了广告。当我不得不改变广告大小时,我已经展示了这个面板。 在刷新广告时(你可以通过回调函数ADREFRESHID截获),我已经隐藏了封面

<StackPanel x:Name="AdsCover" Width="300" Height="50" Visibility="Visible"
                   Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.ZIndex="12" Background="WhiteSmoke">
            <Border x:Name="AdsBorder" BorderBrush="{x:Null}" Height="50">
                <TextBlock x:Name="AdsLoading" Text="Ads Loading..." HorizontalAlignment="Center" FontStyle="Italic" FontFamily="Calibri" FontSize="24"
                       TextAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </StackPanel>
        <UI:AdControl x:Name="adsMS" 
                ApplicationId="3f83fe91-d6be-434d-a0ae-7351c5a997f1"
                AdUnitId="10865270"
                HorizontalAlignment="Left"
                Height="50"
                VerticalAlignment="Bottom"
                Width="300"
                Grid.Column="0" Grid.ColumnSpan="3"
                Canvas.ZIndex="10"
                ErrorOccurred="OnAdErrorOccurred"
                AdRefreshed="OnAdRefreshed"/>
在OnAddressFreshed()回调中,可以隐藏面板

// Called when the Ad is refreshed.
void DirectXPage::OnAdRefreshed(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    // If the Ad is hidden by the cover panel, I will make it visible again.
    if (AdsCover->Visibility == Windows::UI::Xaml::Visibility::Visible)
        AdsCover->SetValue(VisibilityProperty, Windows::UI::Xaml::Visibility::Collapsed);
}