Silverlight Class
Provides a way to integrate Microsoft Silverlight content in an ASP.NET Web page.
Assembly: System.Web.Silverlight (in System.Web.Silverlight.dll)
When you need to add Silverlight content to an ASP.NET Web page, you can use the Silverlight control.
The Source property indicates the Silverlight content to display. This can be specified as a .xap package (with compiled Silverlight 2 content) or as a XAML file (for Silverlight 1.0 content).
Note:
|
|---|
|
Specifying a .xap file as the value for the Source property requires Silverlight 2 to be installed in the browser for the user to view the Silverlight content. |
The ASP.NET Silverlight control generates a Sys.UI.Silverlight.Control client control in the HTML sent to the browser.
The property settings for the Silverlight server control are sent as client property values for the Sys.UI.Silverlight.Control client control in the HTML markup rendered for the .aspx page that has a Silverlight server control.
For example, you can specify the size of the Silverlight plug-in content using the Height and Width properties inherited from the WebControl base class. You can set the width or height as a numeric value (in pixels) or as a percentage.
You can send initialization parameters to the Silverlight plug-in by specifying the values for the InitParameters property.
The Silverlight client Sys.UI.Silverlight.Control class provides automatic detection of whether the Silverlight plug-in is installed on the user's computer. If the correct version of the Silverlight plug-in is not installed, a graphic that is displayed allows the user to click to install the Silverlight plug-in.
You can customize the HTML that is displayed when the required version of the Silverlight plug-in is not installed in the user's browser with the PluginNotInstalledTemplate property.
The following example demonstrates how to use the Silverlight control. The Silverlight control enables you to render a .xap application package which is created using XAML and managed code. For more information about using the Silverlight control with .xap application packages, see ASP.NET Silverlight Server Control.
The following code shows how to include the Silverlight server control in a Web page. The Source attribute of the Silverlight server control references the .xap application package.
<%@ Page Language="C#" AutoEventWireup="true" %> <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;"> <head runat="server"> <title>Test Page For myExample</title> </head> <body style="height:100%;margin:0;"> <form id="form1" runat="server" style="height:100%;"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <div style="height:100%;"> <asp:Silverlight ID="Xaml1" runat="server" Source="../ClientBin/myExample.xap" MinimumVersion="2.0" Width="100%" Height="100%" /> </div> </form> </body> </html>
The following code shows a XAML example (page.xaml) that is included in the .xap application package referenced in the above code.
<UserControl x:Class="myExample.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"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Text="Button Demonstration" Margin="0,20,10,15" FontFamily="Verdana" FontSize="18" FontWeight="Bold" Foreground="#FF5C9AC9" Grid.Row="0" Grid.ColumnSpan="2"/> <Button x:Name="btn1" Grid.Row="1" Margin ="0,5,5,5" HorizontalAlignment="Left" Foreground="Green" Width="120" Click="OnClick1" Content="Hover to Click" ClickMode="Hover" /> <TextBlock x:Name="text1" Grid.Row="1" Grid.Column="1" Margin ="0,8,0,0" /> <Button x:Name="btn2" Grid.Row="2" Margin ="0,5,5,5" HorizontalAlignment="Left" Foreground="Blue" Width="120" Click="OnClick2" Content="Press to Click" ClickMode="Press" /> <TextBlock x:Name="text2" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0" /> <Button x:Name="btn3" Grid.Row="3" Margin ="0,5,5,5" HorizontalAlignment="Left" Click="OnClick3" Width="120" Content="Reset" ClickMode="Release"/> <TextBlock x:Name="text3" Grid.Row="3" Grid.Column="1" Margin ="0,8,0,0" /> </Grid> </UserControl>
The following code shows the supporting code-behind (page.xaml.cs or page.xaml.vb) for the above XAML example (page.xaml).
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 myExample { public partial class Page : UserControl { public Page() { InitializeComponent(); } void OnClick1(object sender, RoutedEventArgs e) { btn1.Foreground = new SolidColorBrush(Colors.Blue); text1.Text = "Click event handled on Hover."; text3.Text = ""; } void OnClick2(object sender, RoutedEventArgs e) { btn2.Foreground = new SolidColorBrush(Colors.Green); text2.Text = "Click event handled on Press."; text3.Text = ""; } void OnClick3(object sender, RoutedEventArgs e) { btn1.Foreground = new SolidColorBrush(Colors.Green); btn2.Foreground = new SolidColorBrush(Colors.Blue); text1.Text = ""; text2.Text = ""; text3.Text = "Click event handled on Release."; } } }
Control
WebControl
System.Web.UI.SilverlightControls.Silverlight
System.Web.UI.SilverlightControls.MediaPlayer
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
