The easiest way to start Silverlight is to create an ordinary website with HTML pages and no server-side code . Here's how
1. Select File--> New-->Project in visual studio , choose the visual c# group of project types, and select the Silverlight Application template . As usual , you need to pick a project name and a location on your hard drive before clicking OK to create the project.
1. Select File--> New-->Project in visual studio , choose the visual c# group of project types, and select the Silverlight Application template . As usual , you need to pick a project name and a location on your hard drive before clicking OK to create the project.
2. At this point , visual studio will prompt you to choose whether you want to create full -fledged ASP.NET website that can run server-side code along with your silverlight . In visual studio , uncheck the "Host the Silverlight application in a website" option to keep things simple.
3. Click OK to continue and create the project.
Every Silverlight project start with a small set of essential files. All the files that end with the extension .xaml use a flexible markup standard called XAML. All the files that end with the extension .cs hold the C# source code that powers your application.
App.xaml and App.xaml.cs files configure your Silverlight application they allow you to resources that will be made available to all the pages in your application, and they allow you to react to application events such as startup, shutdown and error conditions.
MainPage.xaml files defines the user interface(the collection of controls, images, and text) that will be shown for your first page. Technically , Silverlight pages are user controls-custom classes that drive from UserControl. A Silverlight application can contain as many pages as you need - to add more , simply choose project-->Add new item, pick the silverlight User Control template.
Example of Create Simple "Hello World Application" in Silverlight
<UserControl x:Class="SilverlightApplication1.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="Black">
<TextBox Text=" Hello World!" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
Outputxmlns="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="Black">
<TextBox Text=" Hello World!" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
Tidak ada komentar:
Posting Komentar