Sunday, July 19, 2009
Silverlight ASP.NET Server Control Update
Here's a bit more on our ASP.NET Silverlight Control I talked about recently: We now updated this control to not just be compatible with the old control shipped by Microsoft, but to do things you might find useful. Here is a list of changes:
- Default minimum version is now set to 3.0
- Removed the ScaleMode property, since that just isn't supported by Silverlight anymore
- Added the ability to very easily set that a control uses 100% of the available browser space
- Added the ability to fire a storyboard in a splash screen XAML file
- Added the ability to update a string in the splash screen that represents current download progress
Here is an example aspx file containing a Silverlight control (this one is from www.D2SIG.org):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="D2SIGWeb._Default" %>
<%@ Register assembly="SimpleWebControls" namespace="EPS.Web.SimpleControls" tagprefix="cc1" %>
<!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" >
<head runat="server">
<title>D2SIG - Developers & Designers Special Interest Group</title>
</head>
<body>
<form id="form1" runat="server" style="height: 100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:Silverlight ID="Silverlight1" runat="server"
Source="~/ClientBin/D2SIGSL.xap"
DisplayMode="FullBrowser"
SplashScreenSource="~/D2SIGLoading.xaml"
SplashScreenProgressUpdateObjectId="ProgressLabel"
SplashScreenStoryboard="Loading">
</cc1:Silverlight>
</form>
</body>
</
html>Note that there are no div tags required anymore (you can still add them if you want to, but it is handled by the control automatically). Also, no CSS styles have to be defined for the 100% height and width anywhere. Instead, the DisplayMode of the control is set to FullBrowser, which handles the 100% height and width right in all browsers.
Also note that this example fires a storyboard called "Loading", which is inside the resources of the D2SIGLoading.xaml file.
Furthermore, that XAML file has a text run called "ProgressLabel" which is automatically updated with the current download percentage rounded to full numbers. The XAML file has a text run inside a textblock that is defined like this:
<
TextBlock Height="14"
HorizontalAlignment="Center"
Width="45"
Canvas.Top="54"
TextAlignment="Center"
Foreground="#FF646464">
<Run x:Name="ProgressLabel"
FontFamily="Trebuchet MS"
Text="0"/><Run FontFamily="Trebuchet MS" Text="%"/>
</TextBlock>
Note that whatever object is specified as the progress update object must have a Text property of type string. Note that you can create custom objects with that property, which will automatically be updated as progress changes. You could then do whatever you'd like with that value, including parsing it as a number and use that for further calculations.
Posted @ 4:16 PM by Egger, Markus (markus@code-magazine.com) - Comments
Friday, July 17, 2009
A Silverlight 3 ASP.NET Host Control
Silverlight 3 has released, and with it have come some changes. One change is that the handy ASP.NET server control provided with Silverlight 2 is no longer supported. The official recommendation from MS is to simply embed client-side HTML tags (div and object tags) or use JavaScript to create an appropriate Silverlight embedding environment.
There certainly are upsides to that approach (flexibility and more customization), but there also are downsides (the control made things very simple, and it also allowed for code-behind access to properties on the control). Long story short: There really is no downside to having this control. For this reason, we recreated a Silverlight control 1:1 in the Milos Simple Web Controls assembly that you are probably already using in your ASP.NET apps. The control is 100% compatible. In fact, the only thing you have to change is the registration line of the assembly at the top of the .aspx file (the one that declares the "asp" namespace) so it points at SimpleWebControls.dll, rather than System.Web.Silverlight.dll file used by the Silverlight 2 SDK.
Oh, and btw: While we were at it, we made a few small improvements, such as a straightforward way to set the minimum required Silverlight version to 3.0.
Note that this also includes the entire design time experience as well as required resources such as images, XAML, and scripts.
Posted @ 1:44 AM by Egger, Markus (markus@code-magazine.com) - Comments