How to call invalidate with templated items

Jun 2, 2013 at 9:12 AM
Hey guys. Continue to use the control and be very happy with it.

I am trying to integrate ads in my app inline ( blog talking about it here )

I want to put ads every 20 items in my gridview. So I create a template selector and added the base class and all goes well. But now I am having a hard time figuring how to call Invalidate on the template items at page load.

I can walk the gridview and look for each item if it is an "AdControlModel" (my class name, not yours). But I can't call Invalidate on it because it doesn't know the instance object of the adcontrol. That was all added through XAML.

The XAML for the template looks like this:
<DataTemplate x:Key="AdItemDataTemplate">
    <Grid Width="250" Height="250">
        <AdRotatorWin8:AdRotatorControl x:Name="AdRotatorWin8"
                                AdHeight="250"
                                AdWidth="250"
                                DefaultSettingsFileUri="Ads/DisneyBackgroundsAdSettings.xml"
                                SettingsUrl="http://az188945.vo.msecnd.net/disney/DisneyBackgroundsAdSettings.xml" 
                                />
    </Grid> 
</DataTemplate>
But I can't reference the AdRotatorWin8 from C# to call Invalidate.

Does anyone know how to do this? Or better yet a way to not need the Invalidate method at all. :)
Coordinator
Jun 2, 2013 at 11:01 AM
First off, I don't think this was a scenario that this version of AdRotator is really designed for but it should be possible, a simple solution would be to walk the XAML tree for all controls of type AdRotator or with a specific Tag element, use XAML to your advantage here, that way you should be able to call invalidate on all components.

A simpler solution is to create your own user control to host the AdRotator control and expose a dependency property to set the AdSettings URL (if you are using separate configs for each) and in the usercontrol code behind call invalidate.

If you feel like a challenge a better solution may be to sign up for the Alpha for AdRotator V2 which should be any day now, it's redesigned from the ground up to be more flexible and even has an auto start feature (amongst other things), it's also (IMHO) faster than the current control but it is still in development at the moment but fully working (just not as many features yet but the first Alpha will be able to rotate ads)
Jun 2, 2013 at 10:03 PM
Oh I understand it was not built for that scenario. Windows Phone didn't have this scenario at all. But it is the "preferred" way to do ads in Windows 8. You are not supposed to have intrusive ads outside the app. Just make them part of the app experience, hence why I am trying to make this change.

I did find a way to walk the tree and get all the controls that are visible and call invalidate. The problem is that as soon as they scroll off the screen they get reset and don't work again until I call invalidate.

I am not in a hurry to put this update out there, so I can wait for the alpha. Where do you get it? I can put it into my apps and give some feedback. I don't use a lot of the features in the current release, so I will probably be fine with the reduced feature set.
Coordinator
Jun 2, 2013 at 11:56 PM
The link to V2 is on the codeplex homepage or go to "getadrotator.codeplex.com"

Just finished the last work item for the alpha so should have a pre-release nuget out very soon

From: [email removed]
Sent: ‎02/‎06/‎2013 22:03
To: [email removed]
Subject: Re: How to call invalidate with templated items[wp7adrotator:445709]

From: jasonshortphd

Oh I understand it was not built for that scenario. Windows Phone didn't have this scenario at all. But it is the "preferred" way to do ads in Windows 8. You are not supposed to have intrusive ads outside the app. Just make them part of the app experience, hence why I am trying to make this change.

I did find a way to walk the tree and get all the controls that are visible and call invalidate. The problem is that as soon as they scroll off the screen they get reset and don't work again until I call invalidate.

I am not in a hurry to put this update out there, so I can wait for the alpha. Where do you get it? I can put it into my apps and give some feedback. I don't use a lot of the features in the current release, so I will probably be fine with the reduced feature set.