Because, Silverlight 2 also can reference to Microsoft.Expression.Interactivity Assembly which is from Blend 3 library, you can take many advantages of Behaviors model from Silverlight 3 in Silverlight 2 as well. Yes, you can write Behaviors code without version dependency, and it can be referenced by both of Silverlight 2 and 3.

When I found that possibility, I was excited. As you know, Behaviors model brings you a great functionality which might reduce ‘bording-coding’ dramatically. All you have to do is that just copy-paste XAML from Blend 3, absolutely better than Blend 2, And even no code-behind!

I'm going to show you how to make a simple Silverlight 2 application using a simple trigger-action behavior. Create a new Silverlight project, and follow next steps.

Step 1. Referece a Microsoft.Expression.Interactivity Assembly.

Simply, copy a Microsoft.Expression.Interactivity Assembly to any folder to reference from your application. Usually, you can find it C:\Program Files\Microsoft Expression\Blend 3 Preview\Libraries\Silverlight folder if you installed Blend 3 Preview.

Notice that you must rename the assembly file, because Blend 2 can’t recongnize the name contains ‘Microsoft.Expression’. I don’t know why Blend 2 blocks specific assembly names like that. So just rename it say, Interactivy.dll or something. In this example, I renamed Microsoft.Expression.Interactivity.dll to Interactivity.dll. 

After you reference the assembly, you might be encountered an error follow:

It makes you blind in Visual Studio. Don’t panic. :) It’s  just a bug in Visual Studio Designer which already known. However Blend 2 will display it fine, if there was no other errors. Check this out further information.

Step 2. Create a simple trigger-action behavior.

Now, add a class say, ShowMessageBoxAction. It’ll show message box when trigger event raised on associated object.

public class ShowMessageBoxAction : TriggerAction< Dependencyobject>
    #region Message

    /// Gets or sets the Message possible Value of the string object.
    public string Message
        get { return (string)GetValue(MessageProperty); }
        set { SetValue(MessageProperty, value); }

    /// Identifies the Message dependency property.
    public static readonly DependencyProperty MessageProperty =
        new PropertyMetadata("Message")

    #endregion Message

    protected override void Invoke(object parameter)

It has a property which you want to show up, and it ovverides Invoke method which is called when trigger event raised.

Step 3. Add a button with trigger.

Make some UI to check trigger performs well, follow:

    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Click Me">
                <i:EventTrigger EventName="Click">
                    <local:ShowMessageBoxAction Message="Hello Behaviors in Silverlight 2!" />

Step 4. Build & run!

How is it? It works fine like Silverlight 3 does. Also you can use other Behaviors like this as well. Try it after these steps. Yes, now you can use Behaviors in your Silverlight 2 applications.

Here is source code for above. It'll be more helpful rather than my poor English. :)

Posted by gongdo

Submit comment.

  1. Favicon of BlogIcon Hombre Timberland 2012.12.24 12:57  comment URL  Edit/Remove  Submit comment.

    The airport security may also ask you to remove the laptop so that it can be dusted with a special device and tested for explosives, barato timberland.
    and if you don't intend to actually the laptop while on the plane, timberland niños,Traveling is not a Herculean task for you as you can enjoy the Cheap Flights through online way It is not possible for everyone to enjoy flights in current times as the airfares are touching the sky, zapatos timberland.You need to also remember the booking early will help you to snag a cheap seat, Hombre Timberland.
    Related articles:

  2. Favicon of BlogIcon moncler online 2013.01.04 12:41  comment URL  Edit/Remove  Submit comment.

    L'authentification de la tête du roi Henri IV, moncler españa, annoncée par des scientifiques et des historiens à la mi-décembre, moncler outlet, est contestée par l'historien et journaliste Philippe Delorme, moncler online, dans un article publié mercredi par l'Express, moncler. Culture Paris a accueilli plus de 920 tournages en 2010 Culture Le cinéma fran, a connu une fréquentation record en 2010Related articles:

  3. Favicon of BlogIcon moncler chaquetas 2013.01.04 15:02  comment URL  Edit/Remove  Submit comment.

    La maison de disques EMI,, qui produit Pink Floyd depuis quarante ans, moncler españa, a conclu un nouvel accord de cinq ans avec le groupe britannique, moncler. Livres Biographie d'Hemingway : PPDA accusé de plagiat par l'Express Culture Paris a accueilli plus de 920 tournages en 2010Related articles:

  4. Favicon of BlogIcon moncler outlet 2013.01.04 17:37  comment URL  Edit/Remove  Submit comment.

    Le groupe pharmaceutique fran, moncler españa?ais Sanofi-Aventis et sa filiale BiPar Sciences ont annoncé jeudi la publication des résultats définitifs d'une étude de phase II présentant "des données positives" pour un "candidat-médicament" destiné au traitement d'un type de cancer du sein, moncler chaquetas. Santé L'étude qui liait l'autisme et le vaccin ROR était "un trucage" Actu en continu Bulgarie : un sanglier atteint de fièvre aphteuseRelated articles:

  5. Favicon of BlogIcon moncler españa 2013.01.05 21:20  comment URL  Edit/Remove  Submit comment.

    Au moins 22 personnes, donc six enfants,, sont morts lorsque le bus qui les transportait a plongé dans un ravin, moncler, dans l'Etat de Uttarakhand (nord), a indiqué jeudi la police. L'accident, moncler chaquetas, qui s'est produit mercredi soir à une quinzaine de km de la capitale de l'Etat, moncler españa, Dehradun, a fait 19 blessés, moncler online, a précisé un responsable de la police à l'AFP, moncler outlet.Related articles: