Window Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 3 April 2009

Silverlight 3 : Creating Ads using Silverlight Advertising Creation Kit aka SACK – Part 5

Posted on 04:04 by Unknown

First of all thank you very much for your wonderful response for my last four articles on basic lap around articles on Silverlight 3 Beta, now today I am going for fifth one.

We all know how Rich UI and amazing animations can be made using Silverlight Technology, Silverlight is all about richness and jazz on web, so how can Ads [Advertising] will left behind?? , Here you can download Silverlight Advertising Creation Kit which is actually targeted to Silverlight 2, but since we already started our journey for Silverlight 3, so I am directly modifying and going to discuss few samples given in that kit. Below is mix application ad where I have mixed “createTAG” and “ExpandAd” projects together from the SACK Kit. Idea behind is not to replicate something is already there, but to make you aware, so that you can implement and give a way to your wild imaginations and create some knock-out Ads.

Download SACK Bits :

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=0d7c2850-8253-4254-a7c5-214dcfd2768a

Download SACK Publishing and Serving Guide :

http://www.microsoft.com/downloads/details.aspx?FamilyID=5f4e50ec-3923-49f5-9718-bfbcff3c2325&DisplayLang=en

We see few logos or Images everywhere on sites occupying small small sections and are continuously catching our attention, when we click on them, it redirect to us at desired location.To give example, I created small Microsoft MVP ad which redirects me to nomination page and also shows URL on my Page like this :

adck1

Once I click on this Image, it will redirect me to destination URL like this :

adck2

You can see that it redirect me to MVP nomination URL and I have also printed URL on my page in Blue color, looks simple?? yes, it is damm simple, This is what they are calling as SACK ;)

Now lets come to our actual example where I am mixing above example with some animation. I am carrying same bits and images, So I am using some of the images which are already in SACK kit examples like Halo Banner etc.

XAML Code :

<Grid x:Name="LayoutRoot" Background="Transparent" MouseLeave="LayoutRoot_MouseLeave">
        <Grid.Clip>
            <PathGeometry>
                <PathFigure IsClosed="True" StartPoint="0,0">
                    <LineSegment Point="728,0"/>
                    <LineSegment Point="728,90"/>
                    <LineSegment Point="0,90"/>
                </PathFigure>
            </PathGeometry>
        </Grid.Clip>
        <Grid x:Name="Expandable" Height="360" Margin="0,-271,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Grid.RenderTransform>           
            <Image Source="TechEd.png" MouseLeftButtonUp="SwirledBackground_MouseLeftButtonUp" Width="600" Height="600" Margin="0,90,0,0" Opacity=".50" Stretch="Fill" x:Name="SwirledBackground"  />           
        </Grid> 
        <Image Source="haloBanner.jpg" Margin="0,0,0,270" x:Name="BannerImage" MouseMove="BannerImage_MouseMove"/>

</Grid>

Animation for Expanding image like this :

<UserControl.Resources>
        <Storyboard x:Name="AdExpand">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Expandable" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" BeginTime="00:00:00">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="271">
                    <SplineDoubleKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplineDoubleKeyFrame.KeySpline>
                </SplineDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Clip).(PathGeometry.Figures)[0].(PathFigure.Segments)[1].(LineSegment.Point)" BeginTime="00:00:00">
                <SplinePointKeyFrame KeyTime="00:00:00.7000000" Value="728,360">
                    <SplinePointKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplinePointKeyFrame.KeySpline>
                </SplinePointKeyFrame>
            </PointAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Clip).(PathGeometry.Figures)[0].(PathFigure.Segments)[2].(LineSegment.Point)" BeginTime="00:00:00">
                <SplinePointKeyFrame KeyTime="00:00:00.7000000" Value="0,360">
                    <SplinePointKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplinePointKeyFrame.KeySpline>
                </SplinePointKeyFrame>
            </PointAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="AdCollapse">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Expandable" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" BeginTime="00:00:00">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="271"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0">
                    <SplineDoubleKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplineDoubleKeyFrame.KeySpline>
                </SplineDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Clip).(PathGeometry.Figures)[0].(PathFigure.Segments)[1].(LineSegment.Point)" BeginTime="00:00:00">
                <SplinePointKeyFrame KeyTime="00:00:00.7000000" Value="728,90">
                    <SplinePointKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplinePointKeyFrame.KeySpline>
                </SplinePointKeyFrame>
            </PointAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Clip).(PathGeometry.Figures)[0].(PathFigure.Segments)[2].(LineSegment.Point)" BeginTime="00:00:00">
                <SplinePointKeyFrame KeyTime="00:00:00.7000000" Value="0,90">
                    <SplinePointKeyFrame.KeySpline>
                        <KeySpline ControlPoint1="1,0" ControlPoint2="1,1"/>
                    </SplinePointKeyFrame.KeySpline>
                </SplinePointKeyFrame>
            </PointAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>

Right now I have not taken much pain to re-tweak that animation, but yes it can be done as we want it to behave.

C# Code :

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Browser;

namespace SL_ExpandAd
{
    enum ExpandableState { Expanded, Collapsed }; 

    public partial class MainPage : UserControl
    {      
        private int AdState = (int)ExpandableState.Collapsed;

        public String adurl = null;

        public MainPage(StartupEventArgs e)
        {
            InitializeComponent();
            adurl = e.InitParams["TechEdIndia"].ToString();
        }

        private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
        {          
            if (AdState == (int)ExpandableState.Expanded)
            {
                AdCollapse.Begin();
                AdState = (int)ExpandableState.Collapsed;
            }
        }      

        private void BannerImage_MouseMove(object sender, MouseEventArgs e)
        {
            if (AdState == (int)ExpandableState.Collapsed)
            {
                AdExpand.Begin();  
                AdState = (int)ExpandableState.Expanded;
            }
        }

        private void SwirledBackground_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (adurl != String.Empty)
            {
                HtmlPage.Window.Navigate(new Uri(adurl), "_blank");
                HtmlPage.Window.Alert(adurl);
            }
            else
            {
                HtmlPage.Window.Alert("Sorry, TechEd 2009 India Registration is closed !!");
            }
        }
    }
}

Now lets understand C# code, firstly enum ExpandableState { Expanded, Collapsed };  will maintain state whether it is collapsed or not and that is passed as initial values to another variable AdState like this :

private int AdState = (int)ExpandableState.Collapsed;

Then, public String adurl = null;  which is right now null, basically it will hold URL which are passing through “initParams” [Hope you all aware of usage of initParams and how to set it in HTML test page of Silverlight application.], Right now I have declared it like this :

<param name="initParams" value="TechEdIndia=http://www.microsoft.com/india/teched2009/" />

This basically holds like KV pair, you have “TechEdIndia” as key and url is value. we are then fetching that URL like this :

adurl = e.InitParams["TechEdIndia"].ToString();

Remember, I made some changes in Page constructor and in App.xaml.cs like :

private void Application_Startup(object sender, StartupEventArgs e)
       {
           this.RootVisual = new MainPage(e);
       }

I am passing “e” as argument and in MainPage.xaml.cs it is changes to :

public MainPage(StartupEventArgs e) { … }

Using statement

HtmlPage.Window.Navigate(new Uri(adurl), "_blank"); I am redirecting user to the url which we got from initParam and also throwing the same in alert box, as far as pulling that image down and stuff, will be taken care by animation. So final output will be like this :

exad2

Above is the first initial screen once I start my Ad, when I take mouse over that Halo image, by animation given above, it will pull another image like this :

exad1

You can see that “TechEd” image is now rolled down from top Halo image on mouse over.Now I have set URL of TechEd Portal using initParam in my HTML and I have already given explanation about it above, so after clicking on this image it will redirect me to TechEd portal and also will throw an alert like this :

exad3

You can see a small alert showing url below the instance of IE and in IE Instance you can clearly see the TechEd portal. Well thats all about Ads in Silverlight from me, soon I am ending this series with Effects and Deep linking, then I will start with other untalked scenarios. Hope you will find this useful.

Vikram.  

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • First Windows Phone 7 update February 2011 - Small update but Big start
    After tons of rumors and set of predictions on Windows Phone 7 all over Internet, Microsoft came up with first Windows Phone 7 minor update ...
  • The little Story of “I Unlock Joy” event by Microsoft and Pune User Group
      This post is about recent “I Unlock Joy” event happened in Pune which was conducted by Microsoft and Pune User Group. Little History : ...
  • Silverlight On Mobile : Windows Phone 7 Splash Screen and Customization
    After talking about 3D capabilities on Windows Phone 7 using Silverlight in last article , Now I am moving ahead with small but equally impo...
  • Silverlight 5 : Platform Invoke (PInvoke) in Silverlight
      Two days back Microsoft announced availability of Silverlight 5 RC,I encourage you to download bits from here , My friend Pete Brown alr...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 1
    After a long..I am writing blog, I hope and I wish I will resume blogging like I use to in past. Lots of things happened in past few months....
  • MCTS : Microsoft Silverlight 4 Development Exam Guide (70-506) by Packt Publishing
      Hello, After a long time I got chance to come back here.I will soon resume blogging in month of August. Last 4-5 months were horrible due...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 2
    Hope you enjoyed my last article on Speech Capability in Windows Phone 8, Today I am posting another part or you can say little extension t...
  • Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid
    In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to ...
  • Mango : Using DeviceStatus in Windows Phone 7.1
    First of all “Thank You” for your wonderful response and comments on my last article on Silverlight Vs HTML5 ,I hope you like the points I ...
  • Silverlight, HTML5 & Windows 8 : Where we are heading to ?
    This is not the post or yet another post on most happening debate of Silverlight and HTML5, This is just a visit to all of them to realize t...

Blog Archive

  • ►  2013 (4)
    • ►  August (1)
    • ►  April (3)
  • ►  2012 (4)
    • ►  July (1)
    • ►  March (2)
    • ►  January (1)
  • ►  2011 (24)
    • ►  December (1)
    • ►  September (4)
    • ►  August (2)
    • ►  July (1)
    • ►  June (4)
    • ►  May (3)
    • ►  April (3)
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ►  2010 (21)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  September (2)
    • ►  August (4)
    • ►  July (5)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (1)
  • ▼  2009 (49)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (1)
    • ►  May (5)
    • ▼  April (5)
      • DataBinding in Blend 3 for Designers
      • Overview of Live Smooth Streaming,Live Encoding an...
      • Silverlight 3 : DataGrid Programming – Part 7
      • Silverlight 3 : Out of Browser Support – Part 6
      • Silverlight 3 : Creating Ads using Silverlight Adv...
    • ►  March (9)
    • ►  February (4)
    • ►  January (6)
  • ►  2008 (43)
    • ►  December (3)
    • ►  November (9)
    • ►  October (7)
    • ►  September (4)
    • ►  August (2)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  March (3)
    • ►  February (5)
Powered by Blogger.

About Me

Unknown
View my complete profile