Exception on page init when AdRotator control is inisde a panel whose Visibility=Collapsed

Dec 17, 2012 at 8:18 PM

I put my AdRotator control inside a stackpanel that also contains a "close" button, and bind that panel's visibility to a property that's either "Visible" or "Collapsed" depending on whether the user has purchased the "no ads" upgrade. When the stackpanel is Visible the control works fine. However when the panel is collapsed, I get the exception "Value does not fall within the expected range" (stack is listed below):

This occurs after my page's constructor is called but before the page's "Loaded" event happens.


System.ArgumentException at Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(Timeline timeline, DependencyObject target)

at AdRotatorWin8.AdRotatorControl.InitialiseSlidingAnimations() at AdRotatorWin8.AdRotatorControl.AdRotatorControl_Loaded(Object sender, RoutedEventArgs e)


Dec 18, 2012 at 1:51 PM

I'd recommend not putting the AdRotator control in a separate panel, either put it in a separate UserControl and control the visibility of that, or just bind the "isEnabled" property to your trial check to disable it in Paid.

May 26, 2013 at 11:21 PM
I that getting the same error - don't try to Invalidate AdRotator before UI is setted up properly.

In my case I was setting IsEnabled property and Invalidating in the LicenseChanged callback - and this was sometimes called in inaproperiate time.

My solution - use "IsInitialised" property:
            CurrentAppSimulator.LicenseInformation.LicenseChanged +=
                async () =>
                              if (gameplayAd.IsInitialised)
                                  await SetupAd(); // setting IsEnabled and Invalidating