multiple silverlight xaml controls in one aspx page

July 18, 2009

XAML page contains one or more elements that control the layout and

behavior of the page.You arrange these elements hierarchically in a

tree.

System.Windows.Application derived class named App with the

associated App.xaml and App.xaml.cs files; as well as a

System.Windows.Controls.UserControl derived class called Page with

the associated Page.xaml and Page.xaml.cs files.

The App class takes care of the initialization and basically you

assign a new instance of your Page class to the App.RootVisual

property and through the power of Silverlight it appears on your

screen. you can set RootVisual as many times you want. So

Application_Startup can be used to call multiple Silverlight

controls.

In this project there are two xaml files and they will be added to

one aspx page(i.e. Default.aspx page)

My Application Name multipleXaml

Xaml Pages are

Page.Xaml
calender.xaml

Page.Xaml Code will look like

<UserControl x:Class=”multipleXaml.Page
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Width=”200″ Height=”200″>
<Grid x:Name=”LayoutRoot” Background=”White”>
<Ellipse  Fill=”Beige”></Ellipse>
</Grid>
</UserControl>

calender.xaml code will look like

<UserControl

xmlns:basics=”clr-namespace:System.Windows.Controls;assembly=System.W

indows.Controls”  x:Class=”multipleXaml.calender
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Width=”200″ Height=”200″>
<Grid x:Name=”LayoutRoot” Background=”White”>
<basics:Calendar></basics:Calendar>
</Grid>
</UserControl>

Remember xaml control names

(multiplexaml.calender remove applicationName multiplexaml. then it remains calender so calender.xaml name is calender)

calender.xaml name is calender

Page.xaml name is Page (multiplexaml.Page)

Note : Before adding this two controls in Default.aspx page you have to modify

App.xaml.cs file modify the code in Application_Startup method. This will call all xaml controls using

initParams

//remember InitParams key name is ControlId using this silverlight controls will display in Default.aspx page. In Default.aspx design code you will observer use of ControlId term in Silverlight control  it look like InitParameters=”ControlId=calender”


<asp:Silverlight ID=”Silverlight1” runat=”server”Height=”200px” Width=”200px” InitParameters=”ControlId=calender”

Source=”~/ClientBin/multipleXaml.xap” MinimumVersion=”2.0.30523″></asp:Silverlight>

code will look like
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new Page();

if (e.InitParams.ContainsKey(“ControlId“))
{

switch (e.InitParams["ControlId"])
{

case “calender”:  //this calls from  calender.xaml page

this.RootVisual = new calender();

break;

case “Page”:

this.RootVisual = new Page();

break;

//add more pages like this
//case “dropdown”:
//    this.RootVisual = new dropdown();
//    break;

}

}
}

Now goto Default.aspx Page Add Two Silverlight control from Toolbox.
(In Toolbox Silverlight Tab name contain Silverlight,Pointer and

MediaPlayer control).
Add ScriptManager above of the Default.aspx Page

Sample Design code look like

Default.aspx Page Design

<form id=”form1″ runat=”server”>
<div>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>
<table align=”center”>
<tr>
<td>
<asp:Silverlight ID=”Silverlight1” runat=”server”

Height=”200px” Width=”200px” InitParameters=”ControlId=calender”

Source=”~/ClientBin/multipleXaml.xap” MinimumVersion=”2.0.30523″>
</asp:Silverlight>

</td>
</tr>
<tr>
<td>
<asp:Label ID=”Label1″ runat=”server”

Text=”Label”></asp:Label>

</td>
</tr>
<tr>
<td>
<asp:Silverlight ID=”Silverlight2” runat=”server”

Height=”200px” Width=”200px” InitParameters=”ControlId=Page”

Source=”~/ClientBin/multipleXaml.xap” MinimumVersion=”2.0.30523″>
</asp:Silverlight>
</td>
</tr>
</table>

</div>
</form>

Now Run the application .In Default.aspx Page ,the Page.Xaml control

and calender.xaml control will appear.

Happy coding


Silverlight TimeUpDown,TimePicker and TimePicker & RangeTimePickerPopup

July 16, 2009

TimeUpDown is a silverlight control. It uses textbox to allow user to input time and time changes by clicking up and down
spinners.

It allows you to write 1123 and it converts to 11:23 Or 8a and converts to 8:00 AM.

Artilce from

http://www.codeforasp.net/silverlight-timeupdowntimepicker-and-timepicker-rangetimepickerpopup.html

properties:

set “value” will display default time as you mentioned in TimeUpDown control i.e 11:00 AM

“Culture” values can be set to specific cultures only, such as en-GB for English/Great Britain,
en-US for English/United States.

set the TimeFormat used to format the string, as either Short, Long or custom

Format =”Long” looks like 8:59:30 AM
Format =”Short” looks like 11:00 AM
Format =”hh:mm” looks like 11:00

sample code

<Grid x:Name=”LayoutRoot” Background=”White” >

<inputToolkit:TimeUpDown Value =”11:00″ Width=”100″ Culture=”en-US” Format=”Long” >
</inputToolkit:TimeUpDown>

</Grid>

TimePickers

TimePicker is a Silverlight control that allows the user to pickup a time through a Popup.

MaxDropDownHeight is the property of TimePickers used to increase or decrease the height of the popup

<Grid x:Name=”LayoutRoot” Background=”White” >

<inputToolkit:TimePicker Culture=”it-IT” Format=”hh.mm” MaxDropDownHeight=”200″ Margin=”0,12,0,0″>

<Grid x:Name=”LayoutRoot” Background=”White” >

TimePicker & RangeTimePickerPopup

TimePicker is a Silverlight control that allows the user to pickup a time through a Popup.
RangeTimePickerPopup Represents a time picker popup that allows choosing time through 3 sliders: Hours, Minutes and seconds.

Sample code

<inputToolkit:TimePicker Culture=”it-IT” Format=”hh.mm” MaxDropDownHeight=”200″ Margin=”0,12,0,0″>

<inputToolkit:TimePicker.Popup>
<inputToolkit:RangeTimePickerPopup></inputToolkit:RangeTimePickerPopup>
</inputToolkit:TimePicker.Popup>

</inputToolkit:TimePicker>


Silverlight Accordion Panel

July 9, 2009

Accordion in Silverlight

Silverlight Accordian control is same as Ajax Accordian control. The functionality of this control is to expand and collapse the content within the accordian control. The accordion control is a flexible container that consists of a series of collapsible panels, made up of the AccordionItem control.  The AccordionItem control contain header and content to hide and show the data. By Clicking header part, the content will show and hide.

Original article from

http://www.codeforasp.net/silverlight-accordion-panel.html

Ex:

<layoutToolkit:Accordion>

<layoutToolkit:AccordionItem Header= “Item A Header” Content=”Item A Content”></layoutToolkit:AccordionItem>

<layoutToolkit:AccordionItem Header= “Item B Header” Content=”Item B Content”></layoutToolkit:AccordionItem>

</layoutToolkit:Accordion>

In Silverlight Accordion, AccordionItem contain ContentControl, this will add other silverlight controls like HyperlinkButton, Button, Label….

Ex:

<layoutToolkit:Accordion>

<layoutToolkit:AccordionItem Header=”Item B Header”>

<ContentControl>

<StackPanel>

<HyperlinkButton NavigateUri=”http://silverlight.net/GetStarted/”  Content=”silverlight” TargetName=”_blank”></HyperlinkButton>

<HyperlinkButton NavigateUri=”http://www.google.co.in”  Content=”Google” TargetName=”_blank”></HyperlinkButton>

</StackPanel>

</ContentControl>

</layoutToolkit:AccordionItem>

</layoutToolkit:Accordion>

The header and content properties can be specified in a variety of ways.

Sample Code :

<Grid x:Name=”LayoutRoot” Background=”White”>

<StackPanel Orientation=”Horizontal” VerticalAlignment=”Top”>

<layoutToolkit:Accordion>

<layoutToolkit:AccordionItem Header= “Item A Header” Content=”Item A Content”></layoutToolkit:AccordionItem>

<layoutToolkit:AccordionItem Header=”Item B Header”>

<ContentControl>

<StackPanel>

<HyperlinkButton NavigateUri=”http://silverlight.net/GetStarted/”  Content=”silverlight” TargetName=”_blank”></HyperlinkButton>

<HyperlinkButton NavigateUri=”http://www.google.co.in”  Content=”Google” TargetName=”_blank”></HyperlinkButton>

</StackPanel>

</ContentControl>

</layoutToolkit:AccordionItem>

</layoutToolkit:Accordion>

</StackPanel>

</Grid>


Silverlight StackPanel control

July 8, 2009

Stack Panel

StackPanel is one of the silverlight control. It enables layout of the silverlight panel elements. Stack Panel will arrange other control of the silverlight in horizontal and vertical direction. Orientation property will declare the direction of the stack Panel child controls. By Default, Orientation property is vertical.

Orientation =”Horizontal”

Orientation = “Vertical”

Example:

<StackPanel Margin=”10″  Orientation=”Horizontal” >

<Ellipse Fill=”Purple” Width=”50″ Height=”50″ Margin=”5″></Ellipse>

<Ellipse Fill=”Purple” Width=”50″ Height=”50″ Margin=”5″></Ellipse>

</StackPanel>

<StackPanel Margin=”10″  Orientation=”Vertical”>

<Ellipse Fill=”SandyBrown”  Width=”50″ Height=”50″ Margin=”5″></Ellipse>

<Ellipse Fill=”SandyBrown” Width=”50″ Height=”50″ Margin=”5″></Ellipse>

</StackPanel>

Let arrange some silverlight controls in StackPanel

<StackPanel Orientation=”Horizontal” VerticalAlignment=”Top”>

<Button Width=”100″ Height=”30″ Content=”Button1″></Button>

<Button Width=”100″ Height=”30″ Content=”Button2″></Button>

</StackPanel>

We can change VerticalAlignment Bottom,center,stretch,Top.

By Default verticalAlignment is center.


Silverlight Grid Layout

July 6, 2009

The grid is a layout control is a container of other silverlight controls. Grid acts like Html table, it places other silverlight controls like Textbox, Checkbox, and Button …

I am going to create 2 rows and 6 columns using Grid layout control

<UserControl xmlns:controls=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit”  x:Class=”ExpanderControl.grid”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

Width=”400″ Height=”400″>

<Grid x:Name=”LayoutRoot” Background=”White” ShowGridLines=”True”  >

<Grid.RowDefinitions>

<RowDefinition Height=”30″></RowDefinition>

<RowDefinition Height=”30″></RowDefinition>

<RowDefinition Height=”30″></RowDefinition>

<RowDefinition Height=”30″></RowDefinition>

<RowDefinition Height=”30″></RowDefinition>

<RowDefinition Height=”30″></RowDefinition>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition Width=”200″></ColumnDefinition>

<ColumnDefinition Width=”200″></ColumnDefinition>

</Grid.ColumnDefinitions>

<controls:Label x:Name=”lblr0c0″   Content=”User Registration” Grid.Row=”0″ Grid.Column=”0″ Margin =”-40,5,5,5″ Grid.ColumnSpan=”2″ HorizontalAlignment=”Center” ></controls:Label>

<controls:Label x:Name=”lblr1c0″   Content=”FirstName” Grid.Row=”1″ Grid.Column=”0″ Margin =”100,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr1c1″   Content=”Text” Grid.Row=”1″ Grid.Column=”1″ Margin =”10,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr2c0″   Content=”LastName” Grid.Row=”2″ Grid.Column=”0″ Margin =”100,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr2c1″   Content=”Text” Grid.Row=”2″ Grid.Column=”1″ Margin =”10,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr3c0″   Content=”DOB” Grid.Row=”3″ Grid.Column=”0″ Margin =”100,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr3c1″   Content=”Text” Grid.Row=”3″ Grid.Column=”1″ Margin =”10,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr4c0″   Content=”Gender” Grid.Row=”4″ Grid.Column=”0″ Margin =”100,5,5,5″ ></controls:Label>

<controls:Label x:Name=”lblr4c1″   Content=”Text” Grid.Row=”4″ Grid.Column=”1″ Margin =”10,5,5,5″ ></controls:Label>

<Button x:Name=”btnTest” Width=”150″ Content=”Register” Grid.Row=”5″ Grid.ColumnSpan=”2″></Button>

</Grid>

</UserControl>

Margin: A value measured by pixels that specifies a uniform Thickness. The uniform value is applied to all four Thickness properties (Left, Top, Right, Bottom).

EX: Margin =”100,5,5,5″

Grid.Colspan will span the columns used in User Registration Title

HorizontalAlignment: alignment of the row

Ex: HorizontalAlignment=”Center”

Result:

register


Starting Silverlight 2.0 using Asp.net 3.5

June 29, 2009

Step1: Open VS2008 –>File –>New –>Project

sl1

Step2: Choose Project Type (Silverlight) –>Right side choose Silverlight Application –>Ok

sl2

step3: choose this  –> Add new Asp.net web Project to the solution to host

Silverlight

Step4: Silverlight Toolkit and Usercontrol window will display

Page.xaml (Silverlight Usercontrol window)

<UserControl xmlns:basics=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls”  x:Class=”SilverlightApplication1.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=”White”>

//Drag silverlight control between this Grid Ex: Calender Control

<basics:Calendar></basics:Calendar>

</Grid>
</UserControl>

Step 5: Run the Project


Silverlight 2.0 Installation in Asp.net 3.5 Framework

June 29, 2009

Install Visual Studio 2008 SP1 or Visual Web Developer Express with SP1install the necessary Visual Studio updates, Silverlight project templates, developer runtime, and SDK.

* Download link for  .NET Framework 3.5 sp1

Silverlight Installations

1) Install Sivlerlight.2.0_Developer.exe

click here to download

2)  Then install Microsoft® Silverlight™ 2 Software Development Kit

Download Link:  Click here

3) Then Install  Silverlight ToolkitMicrosoft® Silverlight™ 2 Tools for Visual Studio 2008 SP1