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