Unified Ad for Windows Phone - Part 4 - GenericAdProviderForXaml

Alright, we have signed up to a lot of Ad Providers in Part 1, setup the Unified Ad control in Part 2 and even implemented the Remote Ad Provider configuration in Part 3. What’s next?

The Generic Ad Provider for Xaml

Think of the Generic Ad Provider as a very simple AdProvider. It can show Xaml and that’s basically it. You could use this Ad Provider for example to market your own applications within your own applications. So a piece of Xaml with a little bit of text and an HyperlinkButton that links to a Uri. And after a minute the Ad Provider will rotate to the next Ad Provider. The Xaml can be much more complex, we will come up to that in a moment. But first see a small example Ad in Xaml.

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      Width="480"
      Height="80"
      Background="{StaticResource PhoneBackgroundBrush}">
    <Border BorderBrush="{StaticResource PhoneAccentBrush}"
            BorderThickness="1">
        <Grid>
            <TextBlock Text="WP Unified Ad"
                       Foreground="{StaticResource PhoneAccentBrush}" Margin="0"
                       VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="35"/>
            <HyperlinkButton NavigateUri="http://wpunifiedad.codeplex.com"
                             HorizontalAlignment="Stretch"
                             VerticalAlignment="Stretch">
            </HyperlinkButton>
        </Grid>
    </Border>
</Grid>

Where do we put the Xaml?

Ideal it would be on a remote server. But if you don’t have the remote server or you want to have a fallback ad in case the remote server isn’t available you can use the OfflineContent property of the GenericAdProvider.

If you do have the remote server you can set the XamlUri property to the remote Url. In case you want to some more intelligent stuff, like a special ad for each country, or making sure you do something special for the current application, you can make use of the format parameters. The first {0} argument will be replaced by the ApplicationID and the second {1} argument will be replace by the CountryCode. So let’s say I have a server app that returns ads for me, my XamlUri could be configured like this:

http://someurlontheinternet.com/ProvideAd?Country={1}&AppId={0}

If you don’t need one or both arguments you could omit them off course.

Using Phone Styles

If you want to make sure that the advertisements have the same color palette as the Phone settings you can even make use of the usual Phone Resources. Like this example where the Background is set to the PhoneBackgroundBrush and the Border and Text to the PhoneAccentBrush.

<Grid Width="480"
        Height="80"
        Background="{StaticResource PhoneBackgroundBrush}">
    <Border BorderBrush="{StaticResource PhoneAccentBrush}"
            BorderThickness="1">
        <Grid>
            <TextBlock Text="WP Unified Ad"
                        Foreground="{StaticResource PhoneAccentBrush}"
                        Margin="0"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        FontSize="35" />
        </Grid>
    </Border>
</Grid>

How to add links

The easiest way to add a link is to put a HyperlinkButton on top of the full Xaml. You don’t have to give it a visual appearance as long as you make it stretch to the full Ad space. Put the Uri you want to link to in the NavigateUri. What? Yes put the Uri in the NavigateUri. But won’t that only work for navigation inside the application, from page to page? Yes but this is improved navigation.

  • http://anythingontheweb.com” and “https://anythingontheweb.com” will start the WebBrowserTask
  • “marketplace://search/some content” will start the MarketplaceSearchTask with “some content” as query.
  • “marketplace://review” will start the MarketplaceReviewTask for the current application.
  • “marketplace://detail” will start the MarketplaceDetailTask for the current application.
  • “marketplace://detail/5f171b43-6ea8-e011-a53c-78e7d1fa76f8” will start the MarketplaceDetailTask for the application with the mentioned ID.

This will enable you to create simple ads that show a webpage. But if you want more, like for example market your other apps you can do this as well.

Complex Ads

I’m not the best designer, but I know a little about Xaml. So I was interested to see if I could get a more complex Ad working. The below Ad for example has a Storyboard attached that changes the opacity of two elements. Sounds easy, it is easy. Just think about what more nice things you can do instead.

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Width="480"
      Height="80"
      Background="{StaticResource PhoneBackgroundBrush}">
	<Grid.Resources>
		<Storyboard x:Name="Storyboard" AutoReverse="True" RepeatBehavior="Forever">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="One">
				<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:3" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:5" Value="0"/>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Two">
				<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:5" Value="1"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
	</Grid.Resources>
    <Border BorderBrush="{StaticResource PhoneAccentBrush}"
            BorderThickness="1">
        <Grid>
            <Grid x:Name="One">
        		<TextBlock Text="WP Unified Ad"
        			Foreground="{StaticResource PhoneAccentBrush}" Margin="0"
        			VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="35"/>
        	</Grid>
            <Grid x:Name="Two" Opacity="0">
            	<TextBlock Text="by Mark Monster"
            		Foreground="{StaticResource PhoneAccentBrush}" Margin="0"
            		VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="35"/>
            </Grid>
            <HyperlinkButton NavigateUri="http://wpunifiedad.codeplex.com"
                             HorizontalAlignment="Stretch"
                             VerticalAlignment="Stretch"/>
        </Grid>
    </Border>
</Grid>
  • Gravatar Rob de Beir March 1st, 2012 at 08:37
    Thanks for this great tool!

    Any chance to add Millenialmedia? They released a windows phone sdk recently: " http://mmedia.com/platform-sdk/windows-phone"
  • Gravatar Martin March 29th, 2012 at 10:24
    Thanks for your tutorial, but I dont know how to test is The Generic Ad Provider for Xaml working? Moreover, can you show that how to use the OfflineContent?

    thank you very much!!
  • Gravatar Elbrinner May 4th, 2012 at 18:14
    would be very pleased to see an example of offline advertising.
  • Gravatar Mel Grubb June 28th, 2012 at 19:08
    I'm trying to use the Unified ad control to display custom content when there's no network connectivity. The trouble I'm seeing is that the fallback provider still seems to be the first choice when showing ads. My ad is always the first choice instead of the last resort. Since ads are shown for 60 seconds each, this means that a full minute goes by before my own ad goes away. As my app is rather "short-lived", this means I'll almost never get to the "real" ads.

    I see that changeset #13219 was supposed to have done something to this, but I'm still seeing the same behavior.

    Based on previous comments, I think a tutorial around this scenario would be incredibly useful.
  • Vente Maillot de Foot Pas Cher 2013-2014
  • Gravatar michael kors outlet April 10th, 2014 at 18:35
    Obviously you have a stronger ability of pronunciation than the other contestants
  • Gravatar Youth Big Barrel Baseball April 18th, 2014 at 14:03
    C3jjsP [url= http://www.topbatsbay.com]{DeMarini Bats|Easton Bats|Louisville Slugger Bats|Marucci Bats|Mizuno Bats|COMbat Bats|Miken Bats|Worth Bats[/url] HKj7tV.
  • Gravatar home April 21st, 2014 at 16:37
    We can see the grammar and structure in your speech is ....
    <a href=" http://ap.bonaplus.com/profile.php?mode=viewprofile&u=60483" >home</a>
  • Gravatar home April 21st, 2014 at 16:40
    We can see the grammar and structure in your speech is ....
    <a href=" http://forum.francofans.fr/index.php?action=profile;u=189797" >home</a>
  • Gravatar home April 21st, 2014 at 16:43
    We can see the grammar and structure in your speech is ....
    <a href=" http://www.yourhostsucks.com/forums/member.php?s=&action=getinfo&userid=32013" >home</a>
Gravatar