BANGALORE, INDIA: Silverlight 3 Beta enables youto run and create applications for your desktop, which means you can use them without Internet connectivity. You can store and use Silverlight apps locally without having to download extra plug-ins. Besides, Silverlight 3 based apps are able to detect Internet connectivity and react intelligently like caching user data, etc. As these applications run inside a secure sandbox environment with persistent isolated storage, they are quite safe to use.
Implementation
To build a Silverlight 3 based app, you need either Visual studio 2008 SP1 or Visual Web Developer Express 2008 SP1. In this implementation, we have used the latter. Now to add Silverlight 3 application building capability to this IDE, download and install Silverlight 3 Beta Tools for Visual Studio from
http://tinyurl.com/cgzacz.
This will install the runtime and Silverlight 3 Beta SDK. We have used C# as programming language in this demo. Now start Visual Web Developer and create new 'Silverlight Application' project ('SilverlightApplication1'). You need a Web page to host this application, therefore Visual Web Developer Express 2008 prompts either creation of test page or a complete ASP.NET project.
We created ASP.NET project named 'SilverlightApplication1.Web' in this implementation. From the solution explore open two files 'MainPage.xaml' and 'MainPage.xaml.cs'. These are two files that define structure and logic of a Silverlight application. Here is the sample structure of 'MainPage.xaml' file:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel MouseLeftButtonDown="Mouse_Clicked">
<StackPanel.Resources>
<Storyboard x:Name="Storyboard1">
<ColorAnimation Storyboard.TargetName="SolidColorBrush" Storyboard.TargetProperty="Color" From="Gold" To="Silver" Duration="0:0:4" />
</Storyboard>
</StackPanel.Resources>
<StackPanel.Background>
<SolidColorBrush x:Name="SolidColorBrush" Color="Gold" />
</StackPanel.Background>
</StackPanel>
</Grid>
</UserControl>
 |
|
To install Silverlight app locally, simply right click on browser window and click on Install. As shown above, one can add a shortcut to the desktop and Start Menu.
|
In this application, we have created a button click event 'Mouse_Clicked' and storyboard named 'Storyboard1'. This application creates animation on left mouse click. With this event, the Gold color in browser will change to Silver in four seconds. Here is the sample code of 'MainPage.xaml.cs' file that simply initiates animation :
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void Mouse_Clicked(object sender, MouseEventArgs e)
{ Storyboard1.Begin(); }
}
}