代码之家  ›  专栏  ›  技术社区  ›  Vincent

在UWP中单击Microsoft广告时如何获取事件

  •  1
  • Vincent  · 技术社区  · 6 年前

    我正在使用用于XAML的Microsoft广告SDK。我的应用程序现在可以显示广告了。但我想知道当用户点击广告时发生的事件。

    以下事件均不起作用。

    <ads:adControl x:name=“adad”grid.row=“3”applicationID=“”adUnitID=“”
    width=“300”height=“250”adrefreshed=“onadrefreshed”
    errorOccurred=“发生OnErrorOccurred”
    tapped=“onAddApped”onPointerDown=“onAddPointerDown”
    pointerpressed=“OnAdpointInterpressed”/>
    < /代码> 
    
    

    .

        <ads:AdControl x:Name="adAd" Grid.Row="3" ApplicationId="" AdUnitId=""
             Width="300" Height="250" AdRefreshed="OnAdRefreshed" 
             ErrorOccurred="OnErrorOccurred"
             Tapped="OnAdTapped" OnPointerDown="OnAdPointerDown" 
             PointerPressed="OnAdPointerPressed"/>
    

    1 回复  |  直到 6 年前
        1
  •  1
  •   Nico Zhu    6 年前
    WebView enter image description here

    AdControl VisualTreeHelper NavigationStarting

    public static T MyFindListBoxChildOfType<T>(DependencyObject root) where T : class
    {
        var MyQueue = new Queue<DependencyObject>();
        MyQueue.Enqueue(root);
        while (MyQueue.Count > 0)
        {
            DependencyObject current = MyQueue.Dequeue();
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(current); i++)
            {
                var child = VisualTreeHelper.GetChild(current, i);
                var typedChild = child as T;
                if (typedChild != null)
                {
                    return typedChild;
                }
                MyQueue.Enqueue(child);
            }
        }
        return null;
    }
    
    
    private void AdTest_AdRefreshed(object sender, RoutedEventArgs e)
    {
        var ADWebView = MyFindListBoxChildOfType<WebView>(AdTest);
        ADWebView.NavigationStarting += ADWebView_NavigationStarting;
    }
    
    private void ADWebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
    {
        System.Diagnostics.Debug.WriteLine("AD clicked---------------");
    }
    

    OnNavigatedFrom

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);
        ADWebView.NavigationStarting -= ADWebView_NavigationStarting;
    }
    
    推荐文章