Wednesday, May 20, 2009

Introduction to Layouts & Controls in Silverlight 2.0. Part - II

We have seen Layout management in our previous lab. So, continuing with the same lab let’s have introduction to commonly used controls. In this lab, I’ll not be taking all controls.

Bellow is a controls list which we will try out-

1) Border Control : Try out following Example -

Most of the time you will see Border Control is used in templates. Important point to note down here is – If you try to add more than one control within border, you will get exception that “The property Child is set more than once”. So, you will see where ever you want to use more than one control inside border you will have to use some container which allows to include more than one control.

<UserControl x:Class="FirstSLApplication.Page"
  
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
Width="400"Height="300">
    <
GridBackground="Black"x:Name="LayoutRoot"ShowGridLines="True">
        <
Grid.RowDefinitions>
            <
RowDefinition Height="*"/>
            <
RowDefinition Height="*"/>
            <
RowDefinition Height="*"/>
            <
RowDefinition Height="*"/>
        </
Grid.RowDefinitions>
        <
BorderBorderBrush="RosyBrown"BorderThickness="3"Width="300"Height="20"Grid.Row="0" />
        <
BorderBorderBrush="Green"BorderThickness="3"CornerRadius="10,10,10,10"Width="300"Height="20"Grid.Row="1" />
        <
BorderBorderBrush="Yellow"BorderThickness="3"CornerRadius="10,10,10,10"Width="300"Height="20"Grid.Row="2">
            <
StackPanel Orientation="Horizontal"HorizontalAlignment="Center">
                <
EllipseHeight="15"Width="15"Fill="Brown"Margin="5,0,0,0"/>
                <
EllipseHeight="15"Width="15"Fill="Blue"Margin="5,0,0,0"/>
                <
EllipseHeight="15"Width="15"Fill="Bisque"Margin="5,0,0,0"/>
                <
EllipseHeight="15"Width="15"Fill="Green"Margin="5,0,0,0"/>
                <
EllipseHeight="15"Width="15"Fill="HotPink"Margin="5,0,0,0"/>
            </
StackPanel>
        </
Border>
        <
BorderBorderBrush="White"BorderThickness="3"CornerRadius="10,10,10,10"Width="75"Height="50"Grid.Row="3">
            <
ImageSource="Butterfly.jpg"Stretch="Fill"Height="40"Width="65" />
        </
Border>
    </
Grid>
</
UserControl>

2) TextBolck Control : Try out following example -

TextBlock control is a lightweight control which is used to display messages or contents.

<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
TextBlock x:Name="txtSimpleTxBlock" Foreground="Yellow" Text="This is Simple TextBlock" Grid.Row="0"/>
<
TextBlock x:Name="txtSimpleTxBlock" Foreground="Red" FontFamily="Times New Roman" Text="This is Simple TextBlock" Grid.Row="1"/>
<
TextBlock x:Name="txtSimpleTxBlock" Foreground="Green" FontSize="20" Text="This is Simple TextBlock" Grid.Row="2"/>
<
TextBlock x:Name="txtSimpleTxBlock" Foreground="White" FontSize="20" FontFamily="Comic Sans MS" Text="This is Simple TextBlock" Grid.Row="3"/>

</
Grid>
</
UserControl>


3) Button Control : Try out following example -



This is not an ordinary Button control which you had seen in Win Forms or Web Forms. Silverlight Button control is a Container control which can hold other controls inside.





<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
Button Content="Click Me !!" Background="Red" Height="50" Width="200" Grid.Row="0"/>
<
Button Height="50" Width="200" Grid.Row="1">
<
Button.Content>
<
StackPanel Orientation="Vertical">
<
TextBlock Text="Click Me" Foreground="Blue" FontWeight="Bold"/>
</
StackPanel>
</
Button.Content>
</
Button>
<
Button Height="50" Width="200" Grid.Row="2">
<
Button.Content>
<
StackPanel Orientation="Vertical">
<MediaElement Source="/Silverlight.wmv" AutoPlay="True"/>


                </StackPanel>
</
Button.Content>
</
Button>
<
Button Content="Click Me !!" Background="HotPink" Height="50" Width="200" Grid.Row="3" IsEnabled="False"/>
</
Grid>
</
UserControl>



4) CheckBox Control : Try out following example -



CheckBox control is a Container control unlike the simple CheckBox you had seen in Win form and Web form.



<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
CheckBox Content="Click Me !!" Foreground="Yellow" Background="Red" Height="50" Width="100" Grid.Row="0"/>
<
CheckBox Height="50" Width="100" Grid.Row="1">
<
CheckBox.Content>
<
StackPanel Orientation="Vertical">
<
TextBlock Text="Click Me" Foreground="Blue" FontWeight="Bold"/>
</
StackPanel>
</
CheckBox.Content>
</
CheckBox>
<
CheckBox Height="50" Width="100" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<
CheckBox.Content>
<
StackPanel Orientation="Vertical">
<
MediaElement Source="/Silverlight.wmv" AutoPlay="True" Height="50" Width="100"/>
</
StackPanel>
</
CheckBox.Content>
</
CheckBox>
<
CheckBox Foreground="Red" Background="HotPink" Height="50" Width="100" Grid.Row="3" IsEnabled="False">
<
CheckBox.Content>
<
Image Source="Butterfly.jpg"/>
</
CheckBox.Content>
</
CheckBox>
</
Grid>
</
UserControl>


5) RadioButton Control : Try out following example -



RadioButton control is a Container control unlike the simple CheckBox you had seen in Win form and Web form.



<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
RadioButton Content="Click Me !!" Foreground="Yellow" Background="Red" Height="50" Width="100" Grid.Row="0"/>
<
RadioButton Height="50" Width="100" Grid.Row="1">
<
RadioButton.Content>
<
StackPanel Orientation="Vertical">
<
TextBlock Text="Click Me" Foreground="Blue" FontWeight="Bold"/>
</
StackPanel>
</
RadioButton.Content>
</
RadioButton>
<
RadioButton Height="50" Width="100" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<
RadioButton.Content>
<
StackPanel Orientation="Vertical">
<
MediaElement Source="/Silverlight.wmv" AutoPlay="True" Height="50" Width="100"/>
</
StackPanel>
</
RadioButton.Content>
</
RadioButton>
<
RadioButton Foreground="Red" Background="HotPink" Height="50" Width="100" Grid.Row="3" IsEnabled="False">
<
RadioButton.Content>
<
Image Source="Butterfly.jpg"/>
</
RadioButton.Content>
</
RadioButton>
</
Grid>
</
UserControl>


6) TextBox Control : Try out following example -



This is a Simple TextBox control-



<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
TextBox Width="220" Text="This is Simple TextBox !!" Height="25"/>
<
TextBox Width="220" Foreground="Blue" FontWeight="Bold" Text="TextBox with Foreground Color" Height="25" Grid.Row="1"/>
<
TextBox Width="220" Background="Yellow" FontWeight="Bold" Text="TextBox with Background Color" Height="25" Grid.Row="2"/>
<
TextBox Width="220" Text="This is Formated TextBox !!" Height="25" Background="Gray" Foreground="Red" Grid.Row="3" />
</
Grid>
</
UserControl>


7) Slider Control : Try out following example -



Slider control has few important property which you need to consider are as follows -



1) Minimum. 2) Maximum. and 3) Value.



The bellow example is using slider to change the Rotation Transform and Skew Transform of Ellipse programmatically on the ValueChanged Event of Slider.



<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SLBlendFirstApp.Page"
Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

<
Grid x:Name="LayoutRoot" Background="#FF000000">
<
Grid.ColumnDefinitions>
<
ColumnDefinition Width="0.500*"/>
<
ColumnDefinition Width="0.500*"/>
</
Grid.ColumnDefinitions>
<
Grid.RowDefinitions>
<
RowDefinition Height="0.740*"/>
<
RowDefinition Height="0.260*"/>
</
Grid.RowDefinitions>
<
Slider Grid.Row="1" Grid.Column="0" x:Name="Slider1" LargeChange="10" Maximum="360" ValueChanged="Slider1_ValueChanged" />
<
Slider Grid.Row="1" Grid.Column="1" x:Name="Slider2" Maximum="100" LargeChange="10" ValueChanged="Slider2_ValueChanged"/>
<
Ellipse Margin="57,88,63,117" Fill="#FFFFF100" Stroke="#FF000000" Width="200" Height="150" Grid.Row="0" Grid.Column="0" x:Name="El1" RenderTransformOrigin="0.5,0.5">

</
Ellipse>
<
Ellipse Margin="57,88,63,117" Fill="#FF0040FF" Stroke="#FF000000" Width="200" Height="150" Grid.Row="0" Grid.Column="1" x:Name="El2"/>

</
Grid>
</
UserControl>


Open your Page.xaml.cs file and write bellow code on Slider’s ValueChanged event.



private void Slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
RotateTransform rTransform=new RotateTransform();
rTransform.Angle=Slider1.Value;
El1.RenderTransform = rTransform;
}

private void Slider2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
SkewTransform rTransform = new SkewTransform();
rTransform.AngleX = Slider2.Value;
El2.RenderTransform = rTransform;
}



8) ComboBox Control : Try out following example -



This is a container controls as bellow example show the same.



<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SLBlendFirstApp.Page"
Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

<
Grid Background="Black" x:Name="LayoutRoot" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
ComboBox Height="50" Width="150" Background="Red" Grid.Row="0">
<
TextBlock Text="Pravinkumar"/>
<
TextBlock Text="Yash"/>
<
TextBlock Text="Priti"/>
<
TextBlock Text="Manish"/>
<
TextBlock Text="Ramakant"/>
</
ComboBox>
<
ComboBox Height="50" Width="150" Background="Purple" Grid.Row="1">
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Red" Text="Red Says Stop - " FontSize="12"/>
<
Ellipse Height="20" Width="20" Fill="Red"/>
</
StackPanel>
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Yellow" Text="Yellow Says Slow - " FontSize="12"/>
<
Ellipse Height="20" Width="20" Fill="Yellow"/>
</
StackPanel>
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Green" Text="Green Says Stop - " FontSize="12"/>
<
Ellipse Height="20" Width="20" Fill="Green"/>
</
StackPanel>
</
ComboBox>
<
ComboBox Height="50" Width="150" Background="Purple" Grid.Row="2">
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Red" Text="Video - 1" FontSize="12"/>
<
MediaElement Height="20" Width="20" Source="/Silverlight.wmv" AutoPlay="True"/>
</
StackPanel>
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Yellow" Text="Video - 2" FontSize="12" />
<
MediaElement Height="20" Width="20" Source="/Silverlight.wmv" AutoPlay="True"/>
</
StackPanel>
<
StackPanel Orientation="Horizontal">
<
TextBlock Foreground="Green" Text="Video - 3" FontSize="12"/>
<
MediaElement Height="20" Width="20" Source="/Silverlight.wmv" AutoPlay="True"/>
</
StackPanel>
</
ComboBox>
<
ComboBox Height="50" Width="150" Background="Purple" Grid.Row="3">
<
Image Height="20" Width="20" Source="Butterfly.jpg"/>
<
MediaElement Height="20" Width="20" Source="/Silverlight.wmv" AutoPlay="True"/>
<
Ellipse Height="20" Width="20" Fill="Red"/>
<
Image Height="20" Width="20" Source="Butterfly.jpg"/>
<
Image Height="20" Width="20" Source="Butterfly.jpg"/>
</
ComboBox>
</
Grid>
</
UserControl>


And like wise their are many more controls which you can use to design the better UX in Silverlight 2.0.



Imp. Note : I have not covered all the controls here. Controls even you can learn by your own. But just to give you a Sneak-Peak-Preview of Silverlight 2.0 Controls I took this opportunity!!



Now as you have completed writing the third Silverlight Lab, let’s have a closer look on Forth lab – “Creating and applying Styles & Templates in Silverlight 2.0 using Microsoft Expression Blend 2.0.

Introduction to Layouts & Controls in Silverlight 2.0. Part - I

 

In this third lab we will have introduction to Layout management in Silverlight 2.0. Below are the steps –:

In Silverlight 2.0 we have few Layouts as follows -

1) Grid Panel.

2) Canvas.

3) Stack Panel.

To work with these Panels, follow below steps -

1) Create Silverlight 2.0 Project as shown in previous Blog and give name to it as SLLayoutManagement.

2) Add an Image of your choice in Silverlight project as shown bellow -

AddImage

3) We will first have a look at Grid Layout. By using Grid Layout you can arrange the contents in Rows and Columns by Specifying the Margin for the contents to appear perfect on your screen.

4) Open Page.xaml and Start typing bellow code -

<UserControl x:Class="FirstSLApplication.Page"
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="Black" ShowGridLines="True" >
<
Grid.ColumnDefinitions>
<
ColumnDefinition Width="*"/>
<
ColumnDefinition Width="*"/>
<
ColumnDefinition Width="*"/>
</
Grid.ColumnDefinitions>
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
Button Height="50" Width="120" Content="Click To See Time" Grid.Column="0" Grid.Row="0"/>
<
Button Height="50" Width="120" Content="Click To See Time" Grid.Column="0" Grid.Row="1"/>
<
Button Height="50" Width="120" Content="Click To See Time" Grid.Column="0" Grid.Row="2"/>
<
Image Height="75" Width="120" Stretch="Fill" Source="Butterfly.jpg" Grid.Column="1" Grid.Row="0"/>
<
Image Height="75" Width="120" Stretch="Fill" Source="Butterfly.jpg" Grid.Column="1" Grid.Row="1"/>
<
Image Height="75" Width="120" Stretch="Fill" Source="Butterfly.jpg" Grid.Column="1" Grid.Row="2"/>
<
Ellipse Height="75" Width="120" Fill="Yellow" Grid.Column="2" Grid.Row="0"/>
<
Ellipse Height="75" Width="120" Fill="Yellow" Grid.Column="2" Grid.Row="1"/>
<
Ellipse Height="75" Width="120" Fill="Yellow" Grid.Column="2" Grid.Row="2"/>

</
Grid>
</
UserControl>

 


5) Once you are done, hit F5 to test the application of Silverlight 2.0.


Note : If you want to Create new project, please follow the steps to create a new project of Silverlight Or modify the existing one. I am modifying existing one.


1) Now as you have seen how Grid Layout works, let’s have a look at Stack Panel . Stack Panel can be used to arrange the contents either Horizontally or Vertically. The default alignment of the contents using Stack Panel is Vertical.


2) If you are using the same project like I am doing in this demo, please comment out the Grid code and start typing the bellow code in Page.xaml-

<UserControl x:Class="FirstSLApplication.Page"
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="Black" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition Height="*"/>
<
RowDefinition Height="*"/>
</
Grid.RowDefinitions>
<
StackPanel Orientation="Vertical" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center">
<
Ellipse Height="50" Width="100" Fill="Red"/>
<
Ellipse Height="50" Width="100" Fill="Green"/>
<
Ellipse Height="50" Width="100" Fill="Blue"/>
</
StackPanel>
<
StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<
Ellipse Height="50" Width="100" Fill="Yellow"/>
<
Ellipse Height="50" Width="100" Fill="Wheat"/>
<
Ellipse Height="50" Width="100" Fill="BurlyWood"/>
</
StackPanel>
</
Grid>
</
UserControl>

 


3) Once you are done, hit F5 to test the application of Silverlight 2.0.


If you observe above code, we are actually using Stack Panel within Grid Panel !! Exciting !!


Note : If you want to Create new project, please follow the steps to create a new project of Silverlight Or modify the existing one. I am modifying existing one.


1) Now let’s have a look on Canvas Panel. Unlike Grid Panel Or Stack Panel Canvas allows us to place the contents as per our flexibility. So, when we use Canvas for content alignment, we have to remember few properties.


2) First property is : Canvas.Left


3) Second Property is : Canvas.Top


4) If you are using the same project like I am doing in this demo, please comment out the Grid code and start typing the bellow code in Page.xaml.

<UserControl x:Class="FirstSLApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<
Canvas Background="Black" x:Name="LayoutRoot">
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="15" Fill="AliceBlue"/>
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="40" Fill="AntiqueWhite"/>
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="65" Fill="Aqua"/>
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="90" Fill="Aquamarine"/>
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="115" Fill="Azure"/>
<
Ellipse Height="20" Width="20" Canvas.Left="200" Canvas.Top="140" Fill="Beige"/>

<
Ellipse Height="20" Width="20" Canvas.Left="175" Canvas.Top="15" Fill="BlanchedAlmond"/>
<
Ellipse Height="20" Width="20" Canvas.Left="150" Canvas.Top="15" Fill="Blue"/>
<
Ellipse Height="20" Width="20" Canvas.Left="125" Canvas.Top="15" Fill="BlueViolet"/>

<
Ellipse Height="20" Width="20" Canvas.Left="225" Canvas.Top="15" Fill="BurlyWood"/>
<
Ellipse Height="20" Width="20" Canvas.Left="250" Canvas.Top="15" Fill="Yellow"/>
<
Ellipse Height="20" Width="20" Canvas.Left="275" Canvas.Top="15" Fill="Gold"/>
</
Canvas>
</
UserControl>

5) Once you are done, hit F5 to test the application of Silverlight 2.0.


Now as you have completed writing the third Silverlight Lab, let’s have few controls introduction and continue with our third Lab – “Introduction to Layouts & Controls in Silverlight 2.0.

Using Microsoft Expression Blend 2.0 to Design Silverlight 2.0 applications.

 

In this second Lab we will have a closer look on Microsoft Expression Blend 2.0 to create Silverlight 2.0 Application.

As most of you might be knowing that, this tool is majorly used by Designers. To have a better collaboration between Developer & Designer Microsoft has released Microsoft Expression Blend 2.0.

However make one note that if you are designing Silverlight 2.0 application by using Microsoft Expression Blend 2.0, you must first install Microsoft Expression Blend 2.0 SP1.

http://www.microsoft.com/downloads/details.aspx?FamilyId=EB9B5C48-BA2B-4C39-A1C3-135C60BBBE66&displaylang=en

So, Let’s get started with Expression Blend !!

1) Open Microsoft Expression Blend 2.0 and make a choice of Silverlight 2.0 application as below-

BlendSLCrProj

2) Specify application name as SLBlendFirstApp.

3) Now let’s see the different windows and a tool box which is available with Microsoft Expression Blend.

BlendWindows

Following are the four different windows –:

i) Interaction window : It contents Two parts one is States and other is Objects and Timeline. State is nothing but a Visual State Manager to control the look and Feel of Silverlight controls which will appear on the screen. We will have a closer look on Creating Visual States latter.

 Object and Timeline : it shows you what are all objects you have it on Silverlight Page and even it allows you to create, modify, delete Story Boards (Animation), Edit Styles, create styles, Create Templates.

ii) Project Window : Similar to your solution explorer in VS 2008.

iii) Properties Window : Allows you to modify properties of controls.

iv) Resources : Allows you to manage resources at Page Level or Application Level.

4) Now let’s have a look at Tool box –:

ToolBoxBlend 

Now you can have a closer look on the tools and controls which are available. If you want to see more controls, Click Asset Library.

AssetLib

5) Now, let’s work as a Designer and build some nice UX (User Experience) using Expression Blend 2.0.

6) Make a choice of LayoutRoot from Objects and Timeline window. Go to property window and make a choice of background property with Gradient Brush as shown bellow-

BGColor

7) You can Brush Transform to transform the colours as per your need. If you want you can change the colours which are in ARGB (Alpha, Red, Green, Blue) format.

8) Now design a screen like bellow-

BlendOutput

When you design the screen like above, Expression Blend will automatically generate the XAML code for you.

10) Now, the final step is writing some logic on the Click Event of the Button which you can not do by using Microsoft Expression Blend 2.0. So, for that follow the bellow steps and complete your application -

11) In Project window of Expression Blend, Right Click to Project/Solution and make a choice of context menu to Edit in Visual Studio as shown bellow-

EditInVS08

12) Once you do that, In visual studio, open Page.xaml and locate you Login button. Hook up a click event to the button and write a logic which you are suppose to write to finish the application.

<Button Height="60" Margin="280.457,0,145.543,74" VerticalAlignment="Bottom" Content="Login Now !!" FontSize="14" RenderTransformOrigin="0.5,0.5" Click="Button_Click">

13) Once you are done, hit F5 to test the First application of Silverlight 2.0.

Now as you have completed the second lab, let’s start with our third Lab – “Introduction to Layouts & Controls in Silverlight 2.0


Writing First Silverlight 2.0 Program using Visual Studio 2008

 

In this first lab we will create Silverlight 2.0 Application using Visual Studio 2008. Below are the steps –:

1) Create a new project using Visual Studio 2008 as shown below-

CreateProject

2) Give a Name to your Silverlight Project FirstSLApplication and click OK.

3) From the dialog box shown make a choice of Web Site and click OK as shown below-

ChooseWebSite

4) This will create one solution which contains Silverlight Application and web site which is same as Simple ASP.NET 2.0 web site with one significant change that is it has one very special folder – ClientBin. This folder contains .XAP file. Which is a compressed format of Silverlight 2.0 application which will get deployed at client side.

5) Compile your Silverlight application and see that your ClientBin Folder contains .XAP file.

SolExp

6) You can see what is there inside .XAP. Open ClientBin folder in windows explorer and rename the file extension from .XAP to .Zip. Extract that .zip file and observe it. It contains a .dll file by the name of your silverlight application and AppMenifest.xaml.

7) Now as you have seed what is there inside .XAP, let’s go and start writing our first Program.

8) In a silverlight Project, you will find Page.xaml and the code behind Page.xaml.cs/.vb file. Page.xaml will hold the design part of Silverlight application and Page.xaml.cs/.vb will contain the application logic. For example Button Click event, Page Load event.

9) Type the below code in Page.xaml-

<UserControl x:Class="FirstSLApplication.Page"
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="Black">
<
TextBlock FontSize="12" Foreground="White" x:Name="txtName" Text="Show Date and Time"/>
<
Button x:Name="btnShowDateTime" Content="Show Date and Time" Height="50" Width="200" Click="btnShowDateTime_Click"/>

</
Grid>
</
UserControl>



9) Now go to the code behind of Page.xaml.cs and write bellow code-



private void btnShowDateTime_Click(object sender, RoutedEventArgs e)
{
txtName.Text = "Current Date and Time - " + DateTime.Now.ToString();
}


10) Once you are done, hit F5 to test the First application of Silverlight 2.0.



Now as you have completed writing the first Silverlight Application, let’s use the tool which is especially dedicated to Designers which is Microsoft Expression Blend 2.0 and start with our second Lab – “Using Microsoft Expression Blend 2.0 to Design Silverlight 2.0 applications.


Silverlight 2.0 Lab Manuals For Beginners & Intermediates

 

Hi All,

Today I have decided to create LAB Manuals for Silverlight 2.0. So that everybody should take the advantage of the new technologies to build Rich Internet Applications. Most of you might know all these examples but still for the people who are interested learning Silverlight 2.0, I am dedicating these labs for them.

Following is a list for all the labs which I will be preparing:

1

Writing First Silverlight 2.0 Program using Visual Studio 2008.

2

Using Microsoft Expression Blend 2.0 to Design Silverlight 2.0 applications.

3

Introduction to Layouts & Controls in Silverlight 2.0.

4

Creating and applying Styles & Templates in Silverlight 2.0 using Microsoft Expression Blend 2.0.

5

Encoding Media using Expression Encoder and testing with ASP.NET MediaPlayer control.

6

Creating Deep Zoom Application for your Images.

7

Creating and using Resources in Silverlight 2.0.

8

Working with MediaElement control in Silverlight 2.0.

9

Consuming Web Services in Silverlight 2.0.

10

Consuming WCF Services in Silverlight 2.0.

11

Querying data from Collection using LINQ and Silverlight 2.0.

12

Creating and using Splash Screen in Silverlight 2.0.

13

Using Custom Types in XAML.

14

Working with Background Worker in Silverlight 2.0.

15

Working with File Dialog box in Silverlight 2.0.

16

Working with HttpAsyncUpload and HttpAsyncDownload.

17

Communicating between Silverlight 2.0 and ASP.NET 2.0 and Vice versa.

18

Consuming XML Data in Silverlight 2.0.

19

Working with Animation in Silverlight 2.0.

20

Drag & Drop operation in Silverlight 2.0.

21

Introduction to Silverlight 3.0.

 

To work with these labs you should have following tools installed on your machine.

1) Microsoft Visual Studio 2008 with SP1.

2) Silverlight 2.0.

http://www.microsoft.com/downloads/details.aspx?FamilyID=c22d6a7b-546f-4407-8ef6-d60c8ee221ed&displaylang=en

3) Microsoft Expression Blend 2.0 with SP1.

4) Microsoft Expression Encoder 2.0 with SP1.

5) Microsoft Expression Designer 2.0.

6) Deep Zoom Composer.

http://www.microsoft.com/downloads/details.aspx?FamilyID=457B17B7-52BF-4BDA-87A3-FA8A4673F8BF&displaylang=en

So, Let’s get started !!!