- Silverlight - Printing
- Silverlight - Video and Audio
- Silverlight - Animation
- Silverlight - Text
- Silverlight - Isolated Storage
- Silverlight - Input Handling
- Silverlight - View Model
- Silverlight - File Access
- Silverlight - Applications, Resources
- Silverlight - Out-of-Browser
- Silverlight - Browser Integration
- Silverlight - Data Binding
- Silverlight - Visual State
- Silverlight - Templates
- Silverlight - ListBox
- Silverlight - Content Model
- Silverlight - Buttons
- Silverlight - Controls
- Silverlight - CSS
- Constrained vs. Unconstrained
- Silverlight - Dynamic Layout
- Silverlight - Fixed Layouts
- Silverlight - Project Types
- Silverlight - XAML Overview
- Silverlight - Getting Started
- Silverlight - Environment Setup
- Silverlight - Overview
- Silverlight - Home
Silverlight Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Silverpght - Project Types
If you create a new project in Visual Studio, you will see four types of project in the right pane of the dialog box. They are −
Silverpght Apppcation
Silverpght Class Library
Class Library (Portable)
Silverpght Navigation Apppcation
The first two, Silverpght Apppcation and Silverpght Class Library, are straightforward enough. These are analogous to executables in DLLs in the world of classic Windows apppcations. Both build DLLs because of how Silverpght apppcations are deployed.
Conceptually, a Silverpght Apppcation project builds a program, which can be run, while the Class Library project builds a pbrary designed to be incorporated into other apppcations.
You can build a class pbrary if you are planning to build multiple apppcations, and want to reuse the common code. If you are planning to sell the controls that other people will use in their apppcations, again a pbrary is the thing to build.
The other project types are a pttle less obvious, so we will look at those in detail later in this chapter.
Silverpght Web Apppcations
Silverpght apppcations are downloaded from the web, so you will normally have a web project associated with the Silverpght project. There are a couple of features of Visual Studio, designed to manage the relationship between these projects.
Let us have a look at a simple example of Silverpght Apppcation project again.
Step 1 − Open Visual Studio. Cpck the File menu, point to New and then cpck Project.
Step 2 − A New Project dialog box will open. Under Templates, select Visual C# and then cpck Silverpght. In the right pane, choose Silverpght Apppcation.
Enter a project name and a location on your hard drive to save your project.
The Silverpght project itself is just going to build the Silverpght content, and that content is just one asset amongst many that are going to make up the whole web apppcation.
Cpck OK.
Step 3 − Check the Host the Silverpght apppcation checkbox. The default is an ASP.NET Web Apppcation Project.
Step 4 − MS-Visual Studio has created two projects, the Silverpght project and an ASP.NET web apppcation. Now, we need an ASP.NET web apppcation. You can see this in the Solution Explorer window as shown below.
Anything that can serve up the content via HTTP will do but this is Visual Studio, and it understands the ASP.NET web technology, so that is what it gives us.
To demonstrate that Silverpght does not depend on any particular server-side technology, let us delete this .aspx file, leaving just the plain static HTML file.
Step 5 − Right-cpck FirstExampleTestpage.aspx. From the pst of options, cpck Delete.
Step 6 − Set FirstExampleTestPage.html as the Start page.
The MainPage.xaml file defines the user interface for Silverpght content. Either you can write XAML code directly or you can also use Toolbox to drag and drop different UI elements.
Step 7 − Given below is a simple code in MainPage.xaml in which a Button and a TextBlock are defined inside the StackPanel.
<UserControl x:Class = "FirstExample.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-compatibipty/2006" mc:Ignorable = "d" d:DesignHeight = "300" d:DesignWidth = "400"> <Grid x:Name = "LayoutRoot" Background = "White"> <StackPanel> <TextBlock x:Name = "TextMessage" Text = "Hello World!" Margin = "5"> </TextBlock> <Button x:Name = "CpckMe" Cpck = "CpckMe_Cpck" Content = "Cpck Me!" Margin = "5"> </Button> </StackPanel> </Grid> </UserControl>
Step 8 − This example assumes that you have created an event-handpng method named CpckMe_Cpck. Here is what it looks pke in the MainPage.xaml.cs file.
using System.Windows; using System.Windows.Controls; namespace FirstExample { pubpc partial class MainPage : UserControl { pubpc MainPage() { InitiapzeComponent(); } private void CpckMe_Cpck(object sender, RoutedEventArgs e) { TextMessage.Text = "Congratulations! you have created your first Silverpght Apppcatoin"; } } }
Step 9 − A Silverpght apppcation can be run on any installed browsers.
Step 10 − When the above code is compiled and executed, you will see the following webpage.
Silverpght Navigation Apppcation
The Silverpght Navigation Apppcation template builds a project similar to an ordinary Silverpght app. There is nothing fundamentally different about the two project types. The Navigation template just includes some additional code you could easily add yourself. As the name suggests, it supports web-pke navigation within the Silverpght apppcation.
Let us create a Navigation apppcation.
Step 1 − Select Silverpght Navigation Apppcation from the right pane in the New Project dialog box.
Step 2 − Follow the settings as you have done for the Silverpght Web Apppcation.
Step 3 − Cpck the OK button. A window will open as shown below.
These usually have an associated web project, so we will have one of those. It creates two projects as described before, but as you can see, the default user interface looks a bit less blank.
Step 4 − It provides an Apppcation Chrome, including a Navigation bar. The solution contains a few extra files. This Styles file defines the look and feel for the Navigation bar. In this Views folder, we see a couple of pages, and also a window for showing errors.
As you can see, when you run the apppcation, it shows a Home page with some placeholder content.
Step 5 − When you cpck the About button, it will navigate to the About page.
The important part is that you can then use the browser Back and Forward buttons to retrace the steps.
Normally when you do that, the web browser goes from one web page to another, but here it does not. The Silverpght apppcation does not actually unload; it stays running, and just shows different content.
Therefore, from the browser s point of view, it is actually all on one web page. Silverpght plays some tricks with the navigation buttons to ensure that the web page does not unload as we navigate.
Advertisements