2016-07-25 8 views
0

こんにちは私はUWPアプリケーションでMicrosofts Adsを使用しています。 は、私は(hereが説明するように)広告のコントロールが有効な大きさの上にある必要があります理解して私は広告のサイズを変更するために、このコードを書いた:マイクロソフトの広告サイズを変更する

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; 
    } 
} 

これは、コントロールがそれに応じてサイズを変更するが、コントロール内の広告がひどい見えました。私はad.Refresh()を追加しました。しかし、それは事を変えなかった。

誰も知らないのですか?

答えて

1

私は同じ問題に直面しています。 残念ながら、広告は30秒ごとに読み込まれ、30秒後に1回更新することはできません。 これは、Refresh()メソッドの呼び出しが失敗するためです。 私はあなたに役立つことを望む回避策を使用しました。 私は広告の同じサイズ(および位置)のStackPanelで広告を「カバー」しました。このパネルは、広告のサイズを変更する必要があるときに表示されています。 広告のリフレッシュ時に(コールバックAdRefreshedによって傍受することができます)、私はカバーパネルを隠しました。あなたが広告のサイズを変更する必要があるの背後にあるコードでは、

<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"/> 

、あなたはこれを行うことができます。

... 
    // Change the size of the Ad. adsW and adsH are the new size 
    adsMS->SetValue(WidthProperty, 1.0*adsW); 
    adsMS->SetValue(HeightProperty, 1.0*adsH); 
    // Cover panel with the same size 
    AdsCover->SetValue(WidthProperty, 1.0*adsW); 
    AdsCover->SetValue(HeightProperty, 1.0*adsH); 
    AdsBorder->SetValue(HeightProperty, 1.0*adsH); 

    // If the size are changed, I hide the Ad with the panel. 
    // In this way, I can avoid to see the deformed Ad. 
    // m_previousAdsWidth and m_previousAdsHeight are the previous size 
    // of the Ad. 
    if ((m_previousAdsWidth != adsW || m_previousAdsHeight != adsH) 
     && m_previousAdsWidth > 0 && m_previousAdsHeight > 0) 
    { 
     AdsCover->SetValue(VisibilityProperty, Windows::UI::Xaml::Visibility::Visible); 
    } 
    m_previousAdsWidth = adsW; 
    m_previousAdsHeight = adsH; 
    ... 

をOnAdRefreshedコールバックでは()あなたはパネルを非表示にすることができます

// 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); 
} 
+0

これは私をいくらか助けました、ありがとう! –

関連する問題