Tuesday, March 03, 2009

IronPython + SilverlightFX

{

SilverlightFX is an interesting library for declaratively attaching behaviors to objects in XAML. People new to the Silverlight world will like how they can use it to get simple animations out of simple code. Here's a step by step:

1. If you don't have it done already, set up an IronPython / Silverlight project.

2. Download SilverlightFX

3. Copy SilverlightFX binaries into your /app directory.

3. Edit the AppManifest.xaml to include the SilverlightFX binaries. Here is an example:

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RuntimeVersion="2.0.31005.00"
EntryPointAssembly="Microsoft.Scripting.Silverlight"
EntryPointType="Microsoft.Scripting.Silverlight.DynamicApplication">
<Deployment.Parts>
<!-- Add additional assemblies here -->
<AssemblyPart Source="Microsoft.Scripting.ExtensionAttribute.dll" />
<AssemblyPart Source="Microsoft.Scripting.Silverlight.dll" />
<AssemblyPart Source="Microsoft.Scripting.Core.dll" />
<AssemblyPart Source="Microsoft.Scripting.dll" />
<AssemblyPart Source="IronPython.dll" />
<AssemblyPart Source="IronPython.Modules.dll" />
<AssemblyPart Source="System.Windows.Controls.dll" />
<AssemblyPart Source="System.Windows.Controls.Data.dll" />
<AssemblyPart Source="Silverlight.FX.dll" />
</Deployment.Parts>
</Deployment>


4. Edit your app.xaml file to include references to the SilverlightFX namespaces. Here is an example:



<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="System.Windows.Controls.UserControl"
xmlns:fxui="clr-namespace:Silverlight.FX.UserInterface;assembly=Silverlight.FX"
xmlns:fxeffects="clr-namespace:Silverlight.FX.UserInterface.Effects;assembly=Silverlight.FX"
>


5. Party on with some declarative effects.



<Border Grid.Row="1" x:Name="redRect" Opacity="0.2">
<TextBlock x:Name="outPut" TextWrapping="Wrap"
Text="Lorem ipsum dolor sit amet,..." />
<fxui:Interaction.Behaviors>
<fxui:HoverEffect>
<fxeffects:Fade FadeOpacity="1" />
</fxui:HoverEffect>
</fxui:Interaction.Behaviors>
</Border>


6. Read Nikhil's related blog entries.



}

1 comment:

Unknown said...

Thanks David! I was able to get this to work. One change...the fxui namespace for Silverlight is "clr-namespace:SilverlightFX.UserInterface;assembly=SilverlightFX">". The same goes for fxeffects.