Introduction To Silverlight in ASP.Net

Introduction

Silverlight is a web-based technology that allows web designers and web developers to explore the boundaries of web application development. It is an integration of rich user interface of desktop applications, where we use the HTML and JavaScript web languages. Silverlight helps in building web applications that contain high-fidelity multimedia content and eye-catching visual effects.

Architecture of Silverlight

Architecture of Silverlight

We will make a simple Silverlight application in Visual Studio 10. Open Visual Studio 10.

Create a New Project by pressing Ctrl + Shift + N, under C# go to Silverlight and choose Silverlight application. Name it Silverlight_demo.

New Project

This is your main page.XAML page where you will write your design code. It is very similar to a default .aspx page where we write design code in ASP.NET.

XAML page

These are the main default files that exist when you create a new project.

Default files

This is your mainpage.xaml page code.

<UserControl x:Class="SilverlightApplication4.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox Height="60"
                 HorizontalAlignment="Left"
                 Margin="28,104,0,0"
                 Name="textBox1"
                 Text="Welcome here for getting Silverlight"
                 VerticalAlignment="Top"
                 Width="343"
                 FontWeight="Bold"
                 Background="#FF89FF89"
                 Foreground="#FF1847D1"
                 Padding="12"
                 FontSize="15" />
    </Grid>
</UserControl>

The design will look like the following.

Design

Now open your MainPage.Xaml.cs page to make some server-side code for your textbook. Add your code after the InitializeComponent() in the constructor.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication4
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Default constructor
            InitializeComponent();

            // Add our textblock code here:
            TextBlock txtBlock = new TextBlock()
            {
                Name = "textBox1",
                Text = "Welcome here for Getting Silverlight",
                Foreground = new SolidColorBrush(Colors.Blue),
            };

            // Add the text block to the visual tree
            this.Children.Add(txtBlock); // Assuming you want it on the MainPage
        }
    }
}

By pressing F5 you will get your output something like the following.

Output

Summary

In this article, we learned about the introduction To Silverlight in ASP.Net with examples.


Similar Articles