none
AdControl takes control over Focus

    Question

  • I was able to scroll listview (when my Mouse is over the scrollbar) until i put the AdControl to the xaml.

    Whenever ad refreshes, user has to click into the listview to be able to scroll again.

    How can i beat this?

    Monday, September 17, 2012 5:20 PM

Answers

All replies

  • As i see, this is still an unresolved problem. If there are really no workarounds i have to remove ads for now..

    How do you guys solve this problem? (Those have ads in their apps)

    Wednesday, September 19, 2012 9:00 AM
  • try to set IsEnabled property to false.

    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 20, 2012 6:58 AM
  • try to set IsEnabled property to false.

    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Strangely it worked. Wouldn't it ignore Mouse clicks and touches if it's disabled? It does not ignore (which is ofcourse what i want). Is this a special case for AdControl?

    Are there any disadvantages setting IsDisabled to false?

    Why people are trying to unload and load AdControl on every page change? Your method seems to be working on multi-page apps.

    Thursday, September 20, 2012 10:15 AM
  • Hi ELRaymod,

    many customers ask this question to me, I have not found the reason why IsEnabled property could work, I find the solution by accidentally.

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 20, 2012 10:21 AM
  • ElRaymod

    I had the same questions, some digging got me to this post on the ad forums. Apparantly this is the correct workaround for now. The disadvntage to setting it to false is that the user will not be able to tab to your ad, but it looks like everything else will work fine

    Hope this helps! Made me feel better about setting IsEnabled to false.

    Sunday, October 14, 2012 10:33 PM
  • Found a slightly more effective workaround (which lets you leave the AdControl fully enabled).

    1. Create a Boolean field to called "_advertRefreshed".
    2. During ApplyTemplates hook the AdControl.Refreshed event, setting the _advertRefreshed true.
    3. Add a OnLostFocus event which implements the logic "if current focus is WebView and _advertRefreshed is true set focus back to original, then following this test always set _advertRefreshed false again".

    For example....

     
        ...
    
            private bool _advertRefreshed;
    
        ...
    
            /// <summary>
            /// Performs additional initialization after the control hierarchy is fully populated.
            /// </summary>
            protected override void OnApplyTemplate()
            {
                 // Load template
                 base.OnApplyTemplate();
    
                 // Initialize advert control
                 ...
                 _advert.IsTabStop = true;
                 _advert.IsTapEnabled = true;
                 _advert.IsEnabled = true;
                 _advert.AdRefreshed += OnAdvertRefreshed;
            }
    
            /// <summary>
            /// Tracks when the advert control is refreshed, used by <see cref="OnLostFocus"/>
            /// to workaround an issue with the current Advertising SDK stealing focus.
            /// </summary>
            private void OnAdvertRefreshed(object sender, RoutedEventArgs e)
            {
                _advertRefreshed = true;
            }
    
            /// <summary>
            /// Handles un-desired focus change events.
            /// </summary>
            protected override void OnLostFocus(RoutedEventArgs e)
            {
                // Prevent advertising control from stealing focus during refresh
                var original = e.OriginalSource as Control;
                if (original != null)
                {
                    var current = FocusManager.GetFocusedElement();
                    var currentAdvert = current as WebView;
                    if (currentAdvert != null && _advertRefreshed)
                    {
                        // Return focus to original control when stolen
                        original.Focus(FocusState.Programmatic);
                        return;
                    }
                }
    
                // Reset advert refresh tracking
                _advertRefreshed = false;
    
                // Continue with valid focus change
                base.OnLostFocus(e);
            }
    
    @MSFT - so what's the status of the bug, can we look forward to a fix soon?

    Key Artefacts

    Thursday, November 01, 2012 11:16 PM