Getting Started with Silverlight

[image]

Getting Started with Silverlight
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Microsoft Silverlight is a new cross-browser, cross-platform client technology that helps you design, develop, and deliver media-enabled experiences and rich interactive applications on the Web.

Silverlight appeals to both designers and to developers because it provides a powerful platform that makes it easy to develop Web applications with professional-quality graphics, audio, and video for an engaging user experience. Silverlight also offers powerful tools that will improve the productivity of both designers and developers.

Silverlight in Action

The best way to start learning about Silverlight is to see what you can do with it. In the following video, Silverlight team members demonstrate sample applications, talk about what you can do with Silverlight, and show how you can start designing and developing your own applications.

Silverlight in Action video

To see live Silverlight samples, take a look at the Silverlight Showcase. In addition, you can download working code for other samples from the Silverlight Gallery.

Resources for Getting Started

There are currently two versions of Silverlight, Silverlight 1.0 and Silverlight 1.1 Alpha. Silverlight 1.1 supports more features than 1.0 (for example, .NET Framework support), but it is currently an alpha product. Some of the resources below provide information for both versions of Silverlight while other resources are specific to either 1.0 or 1.1. Note that the term "Silverlight" without a version number refers to Silverlight as a whole which encompasses both versions.

  • Silverlight Overview: Briefly describes Silverlight features.

  • First Look: Create a Clock with Silverlight: Walks you through creating a simple Silverlight application.

  • Silverlight Architecture: Overview of the architecture of Silverlight.

  • Silverlight 1.0 - Development with JavaScript: If you are targeting your development at the 1.0 version of Silverlight, this is the place for you. In addition, much of the conceptual material contained in here (e.g. animations, graphics, XAML, etc) is useful to 1.1 developers as well.

  • Silverlight 1.1 Alpha - Development with the .NET Framework: For developers targeting the 1.1 Alpha version of Silverlight.

  • Silverlight Technical Articles: Additional MSDN articles that cover subjects in Silverlight.

Silverlight.net

Silverlight.net is a general Silverlight developer site that mashes together resources like samples, QuickStarts, whitepapers, instructional videos, forums, and blogs. In particular, beginners might like to check out the Silverlight.net QuickStarts.

Tools

All downloads you need for creating Silverlight applications including developer and designer tools are available on Silverlight.net.

Silverlight for Designers

As a designer you can benefit from many of the resources listed above, especially those that cover XAML. XAML is a powerful declarative markup language that is the foundation for creating engaging graphics, animation, and media in Silverlight. XAML is similar to HTML, but it is more powerful and extensible. In addition, there are several professional design tools available to Silverlight designers. You can find these tools on the Silverlight.net site.

See Also

Other Resources

Silverlight Forums


Silverlight Overview

[image]

Silverlight Overview
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Web-based applications have often represented a compromise between creating a high-quality, engaging user interface (UI) and the amount of effort and time that a development team can put into the application. Developers generally believe that browsers simply do not support the interactive and expressive capabilities of a true client-based application. The result is that Web-based applications often do not take full advantage of the capabilities of the user's computer to provide an experience that users find not just functional, but exciting.

But now you can use Microsoft Silverlight. Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiances and rich interactive applications (RIA) for the Web. Silverlight unifies the capabilities of the server, the Web, and the desktop, of managed code and dynamic languages, of declarative and traditional programming, and the power of Windows Presentation Foundation (WPF). The result is a platform that lets you create and deliver sophisticated, cutting-edge applications that users will love. And Silverlight offers you great productivity through familiar tools and technologies based on the .NET Framework.

Silverlight enables you to create a state-of-the-art application that has the following features:

  • It is a cross-browser, cross-platform technology. It runs in all popular Web browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, and Opera, and on Microsoft Windows and Apple Mac OS X.

  • It provides a consistent experience no matter where it runs.

  • It is supported by a very small download that installs in seconds.

  • It streams video and audio. It scales video quality to everything from mobile devices to desktop browsers to 720p HDTV video modes.

  • It includes compelling graphics that users can manipulate-drag, turn, zoom-directly in the browser.

  • It reads data and updates the display, but it doesn't interrupt the user by refreshing the whole page.

Silverlight-based application with rich graphics and user interaction

Whether you are a Web developer or a graphics designer, you will find that Silverlight lets you create these applications using skills you already have and tools you already know. You can use Silverlight markup to create media and graphics, and manipulate them with dynamic languages and managed code. Silverlight also enables you to use professional-quality tools like Visual Studio for coding and Microsoft Expression Blend for layout and graphic design-and lets you share files with all team members.

Note Note:

There are currently two versions of Silverlight, Silverlight 1.0 and Silverlight 1.1 Alpha. Silverlight 1.1 supports more features than 1.0 (e.g. .NET Framework support) but it is currently an alpha product. This overview discusses features from 1.0 and 1.1. For Siliverlight 1.0 specific documentation, see Silverlight 1.0 - Development with JavaScript.

What Is Silverlight?

Silverlight combines multiple technologies into a single development platform that enables you to select the right tools and the right programming language for your needs. Silverlight offers you the following features:

  • WPF and XAML. Silverlight includes Windows Presentation Foundation (WPF) technology, which greatly extends the elements in the browser for creating UI. WPF lets you create immersive graphics, animation, media, and other rich client features, extending browser-based UI beyond what is available with HTML alone. Extensible Application Markup Language (XAML) provides a declarative markup syntax for creating WPF elements.

  • Extensions to JavaScript. Silverlight provides extensions to the universal browser scripting language that provide powerful control over the browser UI, including the ability to work with WPF elements.

  • Cross-browser, cross-platform support. Silverlight runs the same on all popular browsers (on any platform). You can design and develop your application without having to worry about which browser or platform your users have.

  • Integration with existing applications. Silverlight integrates seamlessly with your existing JavaScript and ASP.NET AJAX code to complement functionality you have already created.

  • Access to the .NET Framework programming model and to associated tools. You can create Silverlight-based applications using dynamic languages such as Managed JScript and IronPython as well as languages such as C# and Visual Basic. You can use development tools such as Visual Studio to create Silverlight-based applications.

  • LINQ. Silverlight includes language-integrated query (LINQ), which enables you to program data access using intuitive native syntax and strongly typed objects in .NET Framework languages.

  • If you already use ASP.NET, you can integrate Silverlight with the server and client capabilities of ASP.NET that you are familiar with. You can create server-based resources in ASP.NET and use the AJAX capabilities of ASP.NET to interact with server-based resources without interrupting the user.

Silverlight elements

Running Silverlight-based Applications

Silverlight-based applications run in the browser. Silverlight makes sure that you can run your applications in all modern browsers, without having to create browser-specific code.

To run a Silverlight-based application, users require a small plug-in in their browser. The plug-in is free. If users don't already have the plug-in, they are automatically prompted to install it. The download and installation take seconds and require no interaction from the user except permission to install.

Creating Silverlight-based Applications

You can create Silverlight-based applications using skills you already have and tools that you are already familiar with. You can create Web pages that use both HTML and WPF elements with Silverlight. Like HTML, XAML enables you to create UI for your Web-based application with declarative syntax, with the difference that XAML provides significantly more powerful elements.

Tools for Silverlight-based Applications

You can create Silverlight-based applications using the power of Visual Studio 2008 Beta 2. (Silverlight support for Visual Studio 2008 Beta 2 is available as a plug-in for the IDE.) Visual Studio provides the same tools for Silverlight, such as powerful editors, project management, debugging, and so on, that it already provides for creating applications with the .NET Framework.

Designers can easily leverage the end-to-end capabilities of Expression Studio to design, build, and deliver Silverlight-based applications. Expression Studio has all the capabilities needed to create graphics and media assets, design interactivity, and produce experiences. Expression Blend can generate XAML output, meaning that programmers who use Visual Studio and designers who use Expression Blend can share the same files.

Creating a Silverlight-based application with Microsoft Expression

Create New Project dialog box

Learning More

To see what you can do with Silverlight, see the following:

  • Silverlight Architecture

  • First Look: Create a Clock with Silverlight


First Look: Create a Clock with Silverlight

[image]

First Look: Create a Clock with Silverlight
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This tutorial walks you through the creation of a simple clock using Microsoft Silverlight. The following illustration shows the clock that you will create.

The vector graphics that make up the appearance of the clock are created by using the Extensible Application Markup Language (XAML). XAML is similar to HTML except it is more powerful and extensible. XAML can be typed in manually using Microsoft Visual Studio or Microsoft Notepad, or you can use a visual design tool such as Microsoft Expression Blend. Expression Blend works by creating underlying XAML code, so both methods create the same graphics for the clock.

To complete the first part of this tutorial, select one of the options below:

  • Creating clock graphics using Microsoft Expression Blend.

    -or-

    Creating the graphics directly in XAML.

In the next two steps, you add animations and logic to make the clock work. In Microsoft Silverlight, you can use a browser-interpreted language such as JavaScript or managed code such as C#. This tutorial will show you how to add animations and logic using C#. To learn more about using JavaScript to create Silverlight-based applications, see Silverlight 1.0 - Development with JavaScript.

  • Adding animations.

  • Adding C# code to make the clock work.

Prerequisites

You need the following components to complete this tutorial (available from the Silverlight download site):

  • Microsoft Silverlight 1.1 Alpha.

  • Visual Studio 2008 Beta 2.

  • Microsoft Silverlight Tools Alpha for Visual Studio 2008 Beta 2..

  • Microsoft Expression Blend 2 August Preview.

Creating Clock Graphics Using Expression Blend

Microsoft Expression Blend will speed up the creation of your Silverlight-based application, especially when you're designing graphics and layout.

In this section of the tutorial, you will create the graphics for the clock by using Expression Blend.

The clock consists of the graphical elements shown in the following illustration.

Graphical elements of the clock

These graphics are created with simple elements arranged on a canvas. All the circular graphics, including the clock face, outer rim, bevel, and shadow, are created with Ellipse elements, and the clock hands are created with simple Path elements.

To create a new project in Expression Blend

  1. Start Expression Blend. (Click Start, point to All Programs, point to Microsoft Expression, and then click Microsoft Expression Blend 2 August Preview.)

  2. On the File menu, click New Project. The following dialog box is displayed.

    Create New Project dialog box

  3. In the Name box, type SilverlightClock.

  4. In the Language list, click to choose C# as your programming language.

  5. Select Silverlight 1.1 Client Application and click OK.

    At this point you have an empty project. If you press F5 to run the application, you will only see a blank Web page.

The graphics of the clock consists of layers of overlapping shapes, which create the overall appearance of a clock. To create the clock, you will build the clock up one layer at a time, starting with the lowest layer, which is the shadow of the clock.

The following illustration shows what the shadow of the clock will look like when the sample is complete.

Shadow of the clock

To create the shadow of the clock

  1. Select the Ellipse tool.

    Ellipse tool in Expression Blend

  2. Drag and drop the ellipse on the canvas to create a circle approximately 330 pixels wide and high.

    Drawing an Ellipse in Expression Blend

  3. Change the circle properties. Click the Properties tab, give the circle a fill of black, and set the opacity to 30%.

    Changing the properties of the circle

    The circle now has a fill of semi-transparent black, which will provide the shadow effect.

  4. Change the name of the ellipse to shadowEllipse.

    Renaming the circle in Expression Blend

The illustration below shows the outer rim of the clock when the sample is complete.

Outer rim of the clock

To create the outer rim of the clock

  1. Draw the outer rim circle. The circle for the outer rim is the same size as the shadow circle. Therefore, you can create it by simply making a copy of the shadow circle. To do this, select the shadow circle, press CTRL+C to copy it, and Ctr+V to paste a copy. Rename this ellipse outerRimEllipse.

    Now you will fill outerRimEllipse with a simple gradient. Creating a gradient in Expression Blend consists of several steps.

  2. Create a simple gradient.

    Creating a gradient in Expression Blend

  3. Move the right gradient stop to concentrate the gradient on the left side.

    Moving the gradient stop in Expression Blend

  4. Move outerRimEllipse slightly to the upper left to see the shadow. You will notice a sliver of shadowEllipse visible in the lower right, which creates a shadow effect.

    Viewing the shadow effect

  5. Change the direction of the linear gradient so that it is going from the upper left to the lower right (instead of going from left to right over the circle).

    Changing the direction of the gradient

    The gradient direction is shown in the following illustration.

Now you will create the bevel of the clock. The circle you use to make the bevel will be similar to outerRimEllipse, only a little smaller. The following illustration shows the bevel when the sample is complete.

Bevel of the clock

To create the bevel of the clock

  1. Create a copy of outerRimEllipse. To do this, select outerRimEllipse, press CTRL+C to copy it, and press CTRL+V to paste it. Name the new ellipse bevelEllipse.

  2. Select bevelEllipse and resize it to approximately 290 pixels high and wide to make it slightly smaller than outerRimEllipse.

  3. Position bevelEllipse so that it is in the center of outerRimEllipse.

    Resizing the bevel

    Now you will fill BevelEllipse with a linear gradient.

  4. Create the basic gradient. Because bevelEllipse is a copy of outerRimEllipse, it will already have a gradient applied to it.

  5. Change the color of the left gradient stop to #FF2F2F32, and change the color of the right gradient stop to #FFE4E5F4.

  6. Slide the right gradient stop back to the right-hand end of the gradient.

    Resizing the bevel

    This gradient runs in the same direction as the gradient applied to outerRimEllipse. However, the bevelEllipse gradient goes from dark in the upper-left to light in the lower-right, which is the opposite of the gradient applied to outerRimEllipse. The illustration below shows the direction of the gradient.

    Filling the bevel with a gradient

Next, you will create the face of the clock. The circle you use to make the face will be similar to bevelEllipse, only a little smaller. The following illustration shows the clock face when the sample is complete.

Face of the clok

To create the face of the clock

  1. Create a copy of bevelEllipse. To do this, select bevelEllipse, press CTRL+C to copy it, and press CTRL+V to paste it. Name the new ellipse faceEllipse.

  2. Select faceEllipse and resize it to approximately 270 pixels high and wide to make it slightly smaller than bevelEllipse.

  3. Position faceEllipse so that it is in the center of outerRimEllipse.

    Positioning and resizing the face of the clock

  4. Change the fill of faceEllipse to black.

    Changing the fill of the clock face

    Notice that the addition of this circle makes the bevel visible.

    Visible bevel of clock

Next, you will create the center circle of the clock. The following illustration shows the clock face when the sample is complete.

Center circle of the clock

Center circle of the clock

To create the center circle of the clock

  1. Select the Ellipse tool, and drag the new ellipse on top of the clock face.

  2. Change the name of the new ellipse to centerEllipse.

  3. Set the height and width of centerEllipse to 30.

  4. Set the stroke thickness to 8, and set the stroke to green.

    Creating the center circle of the clock

  5. Position the center circle in the middle of the clock face. To find the center of faceEllipse, select faceEllipse and look for its center point. Then select centerCircle and drag and drop or use the arrow keys to move the centerCircle over the center point of faceEllipse.

    Positioning the center circle of the clock

Next, you will create the hands of the clock.

To create the hands of the clock

  1. Select the Line tool.

    Selecting the Lines tool in Expression Blend

  2. Create the second hand. The minute hand is a thin, red line. Drag a line pointing to the 12 o'clock position. Call the line secondHand and give it a stroke thickness of 5 and a stroke color of red.

    Creating the second hand of the clock

  3. Move the transform center point to the middle of the clock face: The transform center point is the point relative to which transforms are applied. Later, you will animate the clock hands around the center of the clock. Therefore, you need to move the center point of the line to the middle of the clock face. To access the center point of the line, drag the width of the line until you see a white dot in the middle of the line. Then drag the white dot to the middle of the center circle.

    Moving the transform center point of the clock

  4. Create the minute hand by following steps 2 and 3 for the second hand.

    • Make the line approximately the same length as secondHand and position it in the 12 o'clock position, on top of secondHand. Name the line minuteHand.

    • Give minuteHand a stroke thickness of 8 (slightly thicker than secondHand) and a stroke color of green.

    • Place the center point of minuteHand in the center of the clock face, following the instructions in step 3.

  5. Create the hour hand by following the preceding steps for the second hand and the minute hand.

    • Make the line about 2/3 as long as the other clock hands and position it in the 12 o'clock posiition, on top of the other clock hands. Name the line hourHand.

    • Give hourHand a strokethickness of 10 (thicker than the other hands) and a stroke color of green.

    • Place the center point of hourHand in the center of the clock face.

  6. Later, you will add animations that rotate the hands around the clock. This will be done by animating the Angle property of the RotateTransform element that is applied to the clock hand. Because the animation will have to target the correct RotateTransform, you will have to name the RotateTransform elements applied to each of the clock hands. To do this, open the XAML editing view in Expression Blend.

    Accessing XAML code

    The clock hands are created with Path elements. Find the clock hand paths in the XAML. If there is already a RotateTransform applied to the path, give it a name using the syntax in the following code, and leave the rest of the code alone for now. Name the elements secondHandTransform, minuteHandTransform, and hourHandTransform, respectively. If a RotateTransform does not already exist, add one, as shown in the following code.

    Copy image Copy Code
      <!-- Second Hand -->
  <Path x:Name="SecondHand" Stretch="Fill" Stroke="#FFFF0000" StrokeThickness="5" Width="71" Height="54"
  Canvas.Left="149" Canvas.Top="279" Data="M252,242 L298,183" RenderTransformOrigin="1.287,-0.266">
    <Path.RenderTransform>
      <RotateTransform x:Name="secondHandTransform"/>
    </Path.RenderTransform>
  </Path>

At this point, you have created the graphics for the clock. Skip the section below. Next, you will add the animations and logic required to make the clock work.

Creating Clock Graphics Using XAML

Instead of using Microsoft Expression Blend, you can create the graphics for the clock directly in markup language, by using XAML. This section of the tutorial shows how.

Working directly in code to create Silverlight-based applications is easiest when using Visual Studio 2008 Beta 2.

To create a new Silverlight project in Visual Studio 2008 Beta 2

  • If you have not already done so, install Visual Studio 2008 Beta 2.

  • If you have not already done so, install Microsoft Silverlight Tools Alpha for Visual Studio 2008 Beta 2. This provides Silverlight templates that plug into Visual Studio.

  • Open Visual Studio. On the File menu, click New, and then click Project.

  • In the dialog box, click Visual C# and Silverlight on the left-hand pane and Silverlight Project under Templates. Name the project SilverlightClock.

    This will create a blank Silverlight project. Run the project in debugging mode by pressing F5. As expected, a blank Web page opens up. You can end debugging mode by either clicking Debug/Stop Debugging from the menu or by closing the browser window.

Let's start by previewing how to create the graphics for the clock. The clock consists of the graphical elements shown in the following illustration.

Graphical elements of the clock

These graphics are created with simple elements arranged on a canvas. All of the circular graphics such as the clock face, outer rim, bevel, and shadow are created with Ellipse elements, and the clock hands are created with simple Path elements. The graphics are composed of layers of overlapping shapes, which create the overall appearance of a clock. To create the clock, you will build the clock up one layer at a time, starting with the lowest layer (the shadow of the clock).

The following illustration shows what the shadow of the clock will look like when the sample is complete.

Shadow of the clock

To create the shadow of the clock

  • Copy the following code to your XAML page.

    Copy image Copy Code
    <Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:SilverlightClock="clr-namespace:SilverlightClock;assembly=SilverlightClock.dll"
x:Class="SilverlightClock.Page;assembly=SilverlightClock.dll"
Width="640" Height="480"
Background="White"
>
<!-- Clock Shadow -->
<Ellipse Width="332" Height="322"
 Canvas.Left="81" Canvas.Top="119" Fill="#FF000000" Opacity="0.3"/>
</Canvas>
Note Note:

Most XAML code in Silverlight-based applications is not affected by the procedural language you use (for example, C# or JavaScript).

The following illustration shows the results.

Next, you will add the outer rim of the clock. The illustration below shows the outer rim when the sample is complete.

Outer rim of the clock

To add the outer rim

  • Copy the following highlighted code to the XAML page after the ellipse used to create the shadow:

    Copy image Copy Code
    <!-- Clock Shadow -->
<Ellipse Width="332" Height="322"
 Canvas.Left="81" Canvas.Top="119" Fill="#FF000000" Opacity="0.3"/>

<!-- Outer rim --><Ellipse Stroke="#FF000000" x:Name="outerCircle" Width="332" Height="322" Canvas.Left="70" Canvas.Top="108">  <Ellipse.Fill>     <!--This linear gradient creates a subtle shadow effect on the outer rim. -->     <LinearGradientBrush EndPoint="0.196,0.127" StartPoint="0.852,0.814">       <GradientStop Color="#FFC0C0C0" Offset="0.788"/>       <GradientStop Color="#FFE4E5F4" Offset="0.995"/>    </LinearGradientBrush>  </Ellipse.Fill></Ellipse>

    The following illustration shows the results.

    Creating a shadow effect on the outer rim

    As you can see from the illustration, the shadow circle is positioned slightly to the lower right, allowing only a sliver of that circle to be visible from underneath. This results in a shadow effect. Also, notice that a linear gradient is applied to the outer rim circle. This linear gradient is positioned to create the appearance of light coming from the upper left of the circle. The gradient direction is illustrated in the following illustration.

Next, you will add the bevel of the clock. The following illustration shows the bevel when the sample is complete.

Bevel of the clock

To add a bevel to the clock

  • Copy the following code to the XAML page after the ellipse used to create the outer rim:

    Copy image Copy Code
    <!-- Bevel -->
<Ellipse Stroke="#FF000000" Width="290" Height="281" Canvas.Left="92" Canvas.Top="128">
   <Ellipse.Fill>
   <!-- This linear gradient creates a subtle shadow effect on the outer rim. -->
   <LinearGradientBrush EndPoint="0.867,0.848" StartPoint="0.232,0.126">
       <GradientStop Color="#FF2F2F32" Offset="0.01"/>
       <GradientStop Color="#FFE4E5F4" Offset="0.995"/>
   </LinearGradientBrush>
   </Ellipse.Fill>
</Ellipse>

    The following illustration shows the results.

    Creating the bevel

    This circle is slightly smaller than the circle used to create the outer rim, and it is positioned directly over the outer rim circle. In addition, this circle also has a linear gradient applied to it, but this gradient goes from dark in the upper left to light in the lower right. The following illustration shows the direction of the gradient.

    Filling the bevel with a gradient

Next, you will add the face of the clock. The illustration below shows the face when the sample is complete.

Face of the clok

To add the clock face

  • Copy the following code to the XAML file after the last ellipse you added.

    Copy image Copy Code
    <!-- Clock Face -->
    <Ellipse Stroke="#FF000000" Width="271" Height="265" Canvas.Left="101" Canvas.Top="136"
     Fill="#FF000000"/>

    The following illustration shows the results.

    Creating the bevel

    The clock face is simply a black filled circle, slightly smaller than the bevel circle, positioned directly over the other circles. Also, notice that addition of this circle makes the bevel visible.

    Visible bevel of clock

The last step is to add the central circle and clock hands.

To add the central circle and hands

  • Copy the following code to the XAML file after the last code you added.

    Copy image Copy Code
    <!-- Central Clock Circle -->
<Ellipse Fill="#FF000000" Stroke="#FF008000" StrokeThickness="7" Width="32" Height="31"
Canvas.Left="224" Canvas.Top="250"/>

<!-- Second Hand -->
<Path x:Name="SecondHand" Stretch="Fill" Stroke="#FFFF0000" StrokeThickness="5" Width="71" Height="54"
Canvas.Left="149" Canvas.Top="279" Data="M252,242 L298,183" RenderTransformOrigin="1.287,-0.266">
  <Path.RenderTransform>
       <RotateTransform Angle="125" x:Name="secondHandTransform"/>
</Path.RenderTransform>
</Path>

<!-- Minute Hand -->
<Path x:Name="MinuteHand" Stretch="Fill" Stroke="#FF008000" StrokeThickness="8" Width="71" Height="54"
Canvas.Left="149" Canvas.Top="279" Data="M252,242 L298,183" RenderTransformOrigin="1.287,-0.266" >
    <Path.RenderTransform>
        <RotateTransform Angle="125" x:Name="minuteHandTransform"/>
    </Path.RenderTransform>
 </Path>

<!-- Hour Hand -->
<Path x:Name="HourHand" Stretch="Fill" Stroke="#FF008000" StrokeThickness="10" Width="71" Height="40"
Canvas.Left="149" Canvas.Top="279" Data="M252,242 L298,183" RenderTransformOrigin="1.287,-0.266" >
  <Path.RenderTransform>
      <RotateTransform Angle="116.5" x:Name="hourHandTransform"/>
  </Path.RenderTransform>
</Path>

    The following illustration shows the results. The second hand, minute hand, and hour hand are overlapping in this illustration.

    Creating the center circle and clock hands

    In the previous code, the minute hand, hour hand, and second hand share the same values for properties that determine positioning (e.g. Canvas.Top and Canvas.Left). However, the hands differ from one another in size and/or color (for example, the hour hand is thickest because it has the largest StrokeThickness value).

    Notice that all of the hands have a RotateTransform applied to them. This transform enables you rotate the angle of the hand. In the next section, you will animate the angle of this transform, which will make the clock hands move to show the time. Each of the RotateTransform elements have a name (for example, x:Name="hourHandTransform"). This is done so you can associate an animation with the transform. Also, notice that all of the hands have a RenderTransformOrigin value. This property is used to specify the point on the canvas that all transforms are made relative to. Since you are going to rotate the hands around the center of the clock, the value of the RenderTransform property for all hands is given as the center of the clock face.

In the next section, you will add the animations and logic required to make the clock work

Adding Animations

Whether you used Expression Blend to create the graphics for the clock or worked directly in XAML markup, you should now have a clock that looks like the following illustration. Note that the second hand, minute hand, and hour hand are overlapping in this illustration.

Creating the center circle and clock hands

In this section, you will apply animations to the rotation transforms of the clock hands. These rotation animations will make the clock hands rotate around the center of the clock (as you would expect clock hands to do). By specifying the timing of the animations, you can make the hands rotate around the clock in sync with the current time on the computer.

To add animations

  1. Open the XAML file.

    If you used Expression Blend in the previous task, open the XAML file of the project and click the XAML tab.

    Accessing XAML code

    If you used Visual Studio or another editing program in the previous task, open your XAML page from that program.

  2. Add the following code after the root Canvas element to add the clock hand animations.

    Copy image Copy Code
    <Canvas.Triggers>
   <EventTrigger RoutedEvent="Canvas.Loaded">
     <EventTrigger.Actions>
      <BeginStoryboard>
        <Storyboard>
          <!-- This animation targets the hour hand transform -->
          <DoubleAnimation x:Name="hourAnimation"
          Storyboard.TargetName="hourHandTransform"
          Storyboard.TargetProperty="Angle" From="180" To="540"
          Duration="12:0:0" RepeatBehavior="Forever"/>
          <!-- This animation targets the minute hand transform -->
          <DoubleAnimation x:Name="minuteAnimation"
           Storyboard.TargetName="minuteHandTransform"
           Storyboard.TargetProperty="Angle" From="180" To="540"
           Duration="1:0:0" RepeatBehavior="Forever"/>
          <!-- This animation targets the second hand transform  -->
          <DoubleAnimation x:Name="secondAnimation"
           Storyboard.TargetName="secondHandTransform"
           Storyboard.TargetProperty="Angle" From="180" To="540"
           Duration="0:1:0" RepeatBehavior="Forever"/>
         </Storyboard>
      </BeginStoryboard>
    </EventTrigger.Actions>
  </EventTrigger>
</Canvas.Triggers>

    This code creates an event trigger that starts the animations when the Canvas gets loaded into the page (RoutedEvent="Canvas.Loaded"). All of these animations target the Angle property of the respective clock hand transform. The Duration property of each animation is set depending on the desired speed of the animation. For example, for the hour hand transform, the duration of the animation is set for 12 hours, which is the time it takes the hour hand to go completely around the clock. The RepeatBehavior of all of the animations are set to "Forever". Therefore, when the animation completes (the hand goes around the clock), it starts over again and repeats indefinitely.

Run the application now. Notice that the second hand is moving around the clock. The other hands are also moving, but they are moving too slowly to be perceptible.

Making the Clock Work

Although the clock hands are moving at the rate they are supposed to, the clock is not set to the current time. To set the clock, you will need to add some logic using procedural code such as C# or JavaScript. This tutorial uses managed code (C#); however, you can use a browser-interpreted language such as JavaScript if you prefer. To learn more about using JavaScript to create Silverlight-based applications, see Silverlight 1.0 - Development with JavaScript.

To make the clock work

  1. Open the code-behind file:

    If you used Expression Blend to design the graphics, open the C# file from the Project panel.

    Accessing the C# file

    If you used Visual Studio or another editing program for your application, open your C# page from that program.

  2. Copy the following C# code to the code-behind file to add the logic for setting the clock.

    Copy image Copy Code
    // These are the namespaces used in this file.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightClock
{
    public class Page: Canvas
    {
        public void Canvas_Loaded(object sender, EventArgs e)
        {
            // Get a reference to the root canvas.
            Canvas can = sender as Canvas;

            // Get references to all of the animations.
            DoubleAnimation hourAnim = (DoubleAnimation)can.FindName("hourAnimation");
            DoubleAnimation minAnim = (DoubleAnimation)can.FindName("minuteAnimation");
            DoubleAnimation secAnim = (DoubleAnimation)can.FindName("secondAnimation");

            // The current date and time.
            System.DateTime date = DateTime.Now;

            // Find the appropriate angle (in degrees) for the hour hand
            // based on the current time.
            float hourangle = (((float)date.Hour) / 12) * 360 + date.Minute / 2;

            // The transform is already rotated 116.5 degrees to make the hour hand be
            // in the 12 o'clock position. You must build this already existing angle
            // into the hourangle.
            hourangle += 116.5;

            // The same as for the hour angle.
            float minangle = (((float)date.Minute) / 60) * 360;
            minangle += 127;

            // The same for the hour angle.
            float secangle = (((float)date.Second) / 60) * 360;
            secangle += 127;

            // Set the beginning of the animation (From property) to the angle
            // corresponging to the current time.
            hourAnim.From = hourangle;

            // Set the end of the animation (To property)to the angle
            // corresponding to the current time PLUS 360 degrees. Thus, the
            // animation will end after the clock hand moves around the clock
            // once. Note: The RepeatBehavior property of the animation is set
            // to "Forever" so the animation will begin again as soon as it completes.
            hourAnim.To = hourangle + 360;

            // Same as with the hour animation.
            minAnim.From = minangle;
            minAnim.To = minangle + 360;

            // Same as with the hour animation.
            secAnim.From = secangle;
            secAnim.To = secangle + 360;

        }
}
}

Perhaps the trickiest part of the previous code is adjusting the transform angle to take the angle already applied to the clock hand transforms into account. Here is the line of code:

Copy image Copy Code
//The transform is already rotated 116.5 degrees to make the hour hand
//be in the 12 o'clock position. You must build this already existing
//angle into the hourangle.
hourangle += 116.5;

This would take into account the angle already applied in XAML:

Copy image Copy Code
  <!-- Hour Hand -->
  <Path x:Name="HourHand" Stretch="Fill" Stroke="#FF008000" StrokeThickness="10" Width="71" Height="40"
  Canvas.Left="149" Canvas.Top="279" Data="M252,242 L298,183" RenderTransformOrigin="1.287,-0.266" >
    <Path.RenderTransform>
      <RotateTransform Angle="116.5" x:Name="hourHandTransform"/>
    </Path.RenderTransform>
  </Path>

The XAML in this tutorial is only an example-your XAML markup might be different. Because the angles applied to your clock hands can vary depending on how you designed them, you might have to use different values to make your clock hands accurate.

The clock is now finished! Press the F5 keyboard key to run the application.

Debugging Silverlight Applications in Visual Studio 2008 Beta 2

You can create breakpoints and step through the C# code shown in this tutorial by using Visual Studio. To create a breakpoint, click the left margin next to the line of code you want to set the breakpoint on. When you run the application, Visual Studio will pause the application at your designated breakpoint. You can then step through each line of code by pressing the F11 key or by clicking Debug/Step Into from the top menu.

Conclusion

In this tutorial, you have learned how to do the following in Silverlight:

  • Design overlapping vector graphics that create the appearance of a real-life clock.

  • Use gradients to create shadowing and depth.

  • Use animations to add functionality to the clock.

  • Use C# to set the clock to the correct time.

  • Learn how to use XAML and Microsoft Expression Blend.

See Also

Concepts

Silverlight 1.1 Alpha - Development with the .NET Framework
Silverlight 1.0 - Development with JavaScript


Silverlight Architecture

[image]

Silverlight Architecture
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic describes the essential architecture and components of Microsoft Silverlight. Silverlight is not only an appealing canvas for displaying rich and interactive Web and media content to end users. It is also a powerful yet lightweight platform for developing portable, cross-platform, networked applications that integrate data and services from many sources. Furthermore, Silverlight enables you to build user interfaces that will significantly enhance the typical end user experience compared with traditional Web applications.

While Silverlight as a client-side runtime environment seems simple and compact in size, the Silverlight development platform integrates a number of features and complex technologies, making them accessible for developers. To create effective Silverlight-based applications, developers need a working knowledge of the platform architecture. For a comprehensive view of the various tools, technologies, and components available to the Silverlight platform, see this Silverlight application structure.

Note Note:

There are currently two versions of Silverlight, Silverlight 1.0 and Silverlight 1.1 Alpha. Many of the features in this article, including .NET Framework support, are only supported in Silverlight 1.1 which is an alpha product. For specific information on the architecture of Silverlight 1.0, see Silverlight 1.0 Architecture Overview.

This topic acquaints you with the following basics of the Silverlight architecture:

  • The Silverlight platform as a whole.

  • The core presentation components.

  • The .NET Framework for Silverlight components.

  • Additional Silverlight programming features.

  • Information about features provided in the two versions of Silverlight.

  • Related technologies and tools.

The Silverlight Platform

The Silverlight platform as a whole consists of two major parts, plus an installer and update component:

Component | Description
The core presentation framework | Components and services oriented towards the UI and user interaction, including user input, lightweight UI controls for use in Web applications, media playback, digital rights management, and presentation features, including vector graphics, text, animation, and bitmaps. Also includes a DOM API for the Silverlight presentation Canvas and Extensible Application Markup Language (XAML) for specifying layouts.
The .NET Framework for Silverlight | A subset of the .NET Framework that contains components and libraries, including data integration, extensible Windows controls, networking, base class libraries, dynamic language compilation, and the common language runtime (CLR).
The installer and updater | An installation and update control that eases the process of helping first-time users install the application, and provides for low-impact, automatic updates later on.

  • You can see these components of the Silverlight architecture, along with related components and services, in the following diagram.

Silverlight Architecture

There is a particular value in the combined set of tools, technologies, and services included in the Silverlight platform: They make it easier for developers to create rich, interactive, and networked applications. While it is certainly possible to build such applications using today's Web tools and technologies, developers are hindered by many technical difficulties, including incompatible platforms, disparate file formats and protocols, and various Web browsers that render pages and handle scripts differently. A rich Web application that runs perfectly on one system and browser may work very differently on another system or browser, or may fail altogether. Using today's large array of tools, protocols, and technologies, it is a massive and often cost-prohibitive effort to build an application that can simultaneously provide all these advantages:

  • Create the same user experience across browsers and platforms, so that the application looks and performs the same everywhere.

  • Integrate data and services from multiple networked locations into one application.

  • Offer a media-rich, compelling, and accessible user interface (UI).

  • Silverlight makes it much more possible and manageable for developers to build such applications, because it overcomes many of the incompatibilities of current technologies, and provides within one platform the tools to create rich, cross-platform, and integrated applications.

Core Presentation Components

The core presentation features of the Silverlight platform, shown in the previous section and diagram, are listed in the following table with descriptions:

Feature | Description
Input | Handles inputs from hardware devices such as the keyboard and mouse, drawing, or other input devices.
UI rendering | Renders vector and bitmap graphics, animations, and text.
Media | Features playback and management of various types of audio and video files, such as .WMP and .MP3 files.
Controls | Provides for layout and editing of UI controls associated with browsers.
DRM | Enables digital rights management of media assets.
XAML | Provides a parser for XAML markup.

A key means by which developers will interact with this presentation framework is to use XAML to specify presentation details. XAML is the primary point of interaction between the .NET Framework and the presentation layer. To programmatically manipulate the presentation layer, developers can use dynamic scripting languages (such as JavaScript and IronPython) to manipulate the DOM API associated with the Silverlight Canvas object, which represents a visible presentation layer in a Silverlight application. For documentation and examples of working with the Silverlight presentation layer and programming with JavaScript, see the QuickStart documentation for Microsoft Silverlight 1.0 RC.

The .NET Framework for Silverlight

The .NET Framework for Silverlight features, shown in the previous diagram, are described in the following table.

Feature | Description
WPF (Windows Presentation Foundation) | Provides an extensible set of rich controls that extend the features of standard Web browser controls. WPF includes controls for shapes, documents, media, animation, and more.
Data | Supports language-integrated query (LINQ) features, and LINQ for XML (XLinq) features, which ease the process of integrating and working with data from disparate sources. Also supports the use of XML and serialization classes for handling data.
BCL (base class library) | A set of.NET Framework libraries that provide essential programming functions, such as string handling, regular expressions, input and output, reflection, collections, and globalization.
Networking | Provides features to simplify access to remote services and data. This includes a browser object, HTTP request and response object, access to RSS, and extensive Web services support.
CLR (common language runtime) | Provides memory management, garbage collection, type safety checking, and exception handling.
DLR (dynamic language runtime) | Supports the dynamic compilation and execution of scripting languages such as JavaScript and IronPython to program Silverlight-based applications. It includes a pluggable model for adding support for other languages for use with Silverlight.

The .NET Framework for Silverlight is a subset of the full .NET Framework. It provides the essentials of robust, object-oriented application development for application types (such as Internet applications) for which this support has not traditionally been available.

Developers can interact with the .NET Framework for Silverlight layer by writing managed code using languages they already know, including C# and Visual Basic. .NET Framework developers can also access the presentation layer by authoring Visual Studio 2008 Beta 2, or in Microsoft Expression Blend. And they can programmatically manipulate the presentation layer by accessing it through the XAML Canvas object. Writing in managed code, developers have access to the entire range of Silverlight capabilities, including the core presentation layer. For documentation and examples of programming Silverlight with the .NET Framework, see the QuickStart documentation for Silverlight 1.1 Alpha.

Note Currently, .NET Framework support is only in Silverlight 1.1 Alpha. See Versions and Silverlight Features below.

Additional Silverlight Programming Features

Silverlight provides several additional features that help developers create rich and interactive applications, as described in the following table.

Feature | Description
Isolated storage | Provides safe access from the Silverlight client to the local machine's file system. Enables local storage and caching of data isolated to a particular user.
Asynchronous programming | A background worker thread carries out programming tasks while the application is freed up for user interaction.
File management | Provides a safe File Open dialog box, to ease the process of creating safe file uploads.
HTML - managed code interaction | Enables .NET Framework programmers to directly manipulate UI elements in the HTML DOM of a Web page. Web developers can also use JavaScript to call directly into managed code and access scriptable objects, properties, events, and methods.
JSON (JavaScript Object Notation) | Enables developers to call directly from JavaScript to ASP.NET-based Web services.
POX services | Enables calls to simple XML-based Web services.
XML libraries | XMLReader and XMLWriter classes simplify working with XML data from Web services.The XLinq feature enables developers to query XML data directly within .NET Framework programming languages.

Versions and Silverlight Features

Two versions of Silverlight are currently available:

  • Microsoft Silverlight 1.0 Release Candidate. This version (previously released as WPF/E) provides the presentation core features of Silverlight and uses JavaScript for procedural code. See Silverlight 1.0 - Development with JavaScript for more information.

  • Microsoft Silverlight 1.1 Alpha. This version combines the presentation core in version 1.0 with .NET Framework capabilities, and offers the full architecture and feature set described in previous sections. For more information, see the QuickStart documentation for Silverlight 1.1 Alpha.

Related Technologies and Tools

Because Silverlight-based applications are cross-platform, they run in most modern Web browsers, including the following:

  • Microsoft Internet Explorer versions 6.0 and 7.0

  • Mozilla Firefox versions 1.5 and 2.0

  • Apple Safari version 2.0

The following Microsoft applications include special features for Silverlight development:

  • Microsoft Expression Blend. This tool can be used to create and modify the presentation layer of an application by manipulating the XAML canvas and controls, working with graphics, and programming the presentation layer with a dynamic language such as JavaScript.

  • Visual Studio 2008 Beta 2. Visual Studio provides productivity tools for developing applications using managed code in languages such as C# and Visual Basic. All the existing features of Visual Studio are available for Silverlight. In addition, this version of Visual Studio includes Silverlight-specific features, including IntelliSense, debugging, and Silverlight project templates that create and link all required files.

Because Silverlight-based applications are executed in a run-time environment on the client machine, no particular application is required to be installed on the server. However, developers may find that their ability to create rich applications that integrate services and data from multiple sources on the server is enhanced by integrating the following types of services and server-side applications into their Silverlight-based applications:

  • ASP.NET AJAX. This includes a set of controls, services, and libraries for creating rich and interactive Web-based applications.

  • Microsoft ASP.NET Futures. This feature set provides additional functionality to enhance ASP.NET AJAX applications. It includes two controls that are useful for building Silverlight-based applications as part of an ASP.NET application:

    • The ASP.NET Media Control

    • The ASP.NET XAML Control

  • Microsoft Windows Communication Foundation (WCF) services.

  • Internet servers, including Microsoft Internet Information Services (IIS), and the Apache Web server.

  • Internet-based applications and services, including Microsoft ASP.NET, PHP, Windows Streaming Media services, Windows Live services, and other open Web services.

See Also

Concepts

Getting Started with Silverlight
Silverlight 1.1 Alpha - Development with the .NET Framework
Silverlight 1.0 - Development with JavaScript


Silverlight 1.0 - Development with JavaScript

[image]

Silverlight 1.0 - Development with JavaScript
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Microsoft Silverlight is a cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and rich interactive applications for the Web and devices. This SDK provides information for developing with the 1.0 release of Silverlight. Silverlight 1.0 utilizes the XAML markup language and JavaScript to create applications.

Note Note:

Silverlight 1.1 (currently available as an Alpha version) lets you use languages besides JavaScript, including .NET Framework languages such as C# and Visual Basic. See Silverlight 1.1 Alpha - Development with the .NET Framework for more information.

In This Section

  • QuickStart Documentation for Silverlight 1.0 RC

  • Silverlight Overviews and Reference

  • Silverlight Samples

See Also

Concepts

Silverlight 1.1 Alpha - Development with the .NET Framework


Silverlight 1.1 Alpha - Development with the .NET Framework

[image]

Silverlight 1.1 Alpha - Development with the .NET Framework
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

You can write Microsoft Silverlight-based applications in managed code-with any .NET Framework programming language such as C# or Visual Basic-by using the subset of the .NET Framework provided with the Microsoft Silverlight 1.1 Alpha runtime. The decision to write an application in managed .NET Framework code or in a dynamic scripting language (such as JavaScript) can be determined by which language you prefer, and also by which language seems to be the most effective tool for the task at hand, because you can program most Silverlight features using either approach. However, as with traditional .NET Framework and ASP.NET applications, many Silverlight-based applications can be optimized by using a combination of these approaches. As a Silverlight developer, you can choose the most optimal tool and language for your development tasks.

The content in this section provides guidance on using the .NET Framework features included with the Silverlight runtime to develop Silverlight-based applications.

In This Section

Silverlight 1.1 Alpha QuickStart Documentation

Silverlight Reference

See Also

Concepts

Getting Started with Silverlight


Silverlight 1.1 Alpha QuickStart Documentation

[image]

Silverlight 1.1 Alpha QuickStart Documentation
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Microsoft Silverlight QuickStart documentation consists of task-based samples that introduce the features of Silverlight. Each sample demonstrates a feature such as creating a custom control, accessing managed code from JavaScript, or calling a Web service, and explains how you can implement that feature in your Silverlight-based application.

The Silverlight 1.1 Alpha QuickStart documentation on the Microsoft Silverlight Web site focuses on developing a Silverlight-based application using the .NET Framework. The QuickStart topics cover the following tasks:

  • Getting Started with Silverlight Development: Creating a Silverlight project for C# or Visual Basic, debugging your application, viewing Silverlight assemblies with the Visual Studio Object Browser.

  • Building Dynamic User Interfaces with Silverlight: Writing event handlers, creating custom controls, calling Silverlight client APIs with C# or Visual Basic.

  • Networking and Communication in Silverlight: Using the HTTP transport to send and receive Plain Old XML (POX) messages, using a proxy to call an ASP.NET Web service that uses JavaScript Object Notation (JSON).

  • Interaction Between HTML and Managed Code: Accessing the HTML DOM from managed code, calling managed code from JavaScript.

  • Working with XML in Silverlight: Using the .NET Framework for Silverlight to retrieve remote XML content, reading the XML content with XmlReader, and writing it out to a page as XAML content.

  • Working with Isolated Storage in Silverlight: Obtaining an isolated store, manipulating files in isolated storage using the .NET Framework for Silverlight.

  • Additional Programming Tasks: Uploading files, downloading images, and using dynamic languages in your Silverlight-based application.

See Also

Other Resources

Silverlight Samples


Silverlight Reference

[image]

Silverlight Reference
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Microsoft Silverlight offers developers a range of language choices for building applications.You can use a dynamic language such as JavaScript, or you can use managed code with C# or Visual Basic. Managed development with C# and Visual Basic enables you to use a subset of the .NET Framework, and to take advantage of managed-code specific Silverlight assemblies. The reference topics in this section provide information about using managed code in your Silverlight-based applications.

In This Section

Visual Basic Run-Time Support in Silverlight

Describes the members of the Visual Basic run-time library (Microsoft.VisualBasic namespace) that Silverlight supports, and lists the members that are not supported.


Visual Basic Run-Time Support in Silverlight

[image]

Visual Basic Run-Time Support in Silverlight
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Microsoft.VisualBasic namespace contains the classes, modules, constants, and enumerations that constitute the Visual Basic run-time library. These library members provide procedures, properties, and constant values that you can use in your code. Microsoft Silverlight supports the Visual Basic language, but it does not support some of the run-time features. Features that are not supported include the My Namespace, financial functions, and file system functions. The topics in this section describe which run-time features are supported in Silverlight, and which features are not supported.

In This Section

Visual Basic Run-Time Members Supported in Silverlight

Describes the Visual Basic run-time library members that are supported in Silverlight.

Visual Basic Run-Time Members Not Supported in Silverlight

Lists the Visual Basic run-time library members that are not supported in Silverlight.


Visual Basic Run-Time Members Supported in Silverlight

[image]

Visual Basic Run-Time Members Supported in Silverlight
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Microsoft.VisualBasic namespace provides classes as part of the Visual Basic run-time library. This topic describes the library class members that are supported in Microsoft Silverlight.

Microsoft.VisualBasic.Collection

All members of Microsoft.VisualBasic.Collection are supported in Silverlight. This class includes the members shown in the following table.

Note Note:

The Collection object in Silverlight does not support ICollection or IList. Also, the Collection object in Silverlight cannot be serialized.

Member | Description
Add | Adds an element to a Collection object.
Clear | Removes all elements from a Collection object.
Contains | Returns a Boolean value that indicates whether a Collection object contains an element that has a specific key.
Count | Returns an Integer that contains the number of elements in a Collection object. Read-only.
GetEnumerator | Returns an enumerator object, which is used to iterate over a Collection object.
Item | Returns a specific element of a Collection object either by position or by key. Read-only.
Remove | Removes an element from a Collection object.

Microsoft.VisualBasic.ControlChars

All members of Microsoft.VisualBasic.ControlChars are supported in Silverlight. This class includes the members shown in the following table.

Member | Description
Back | Backspace character. You can also use the vbBack constant.
Cr | Carriage-return character. You can also use the vbCr constant.
CrLf | Carriage-return and line-feed character combination. You can also use the vbCrLf constant.
FormFeed | FormFeed character. You can also use the vbFormFeed constant.
Lf | Line-feed character. You can also use the vbLf constant.
NewLine | Newline character. You can also use the vbNewLine constant.
NullChar | Character that has a value of 0 (zero). You can also use the vbNullChar constant.
Quote | Quotation mark character (" or ') that is used to enclose values.
Tab | Tab character. You can also use the vbTab constant.
VerticalTab | VerticalTab character. You can also use the vbVerticalTab constant.

Microsoft.VisualBasic.Conversion

The following table shows the members of Microsoft.VisualBasic.Conversion that are supported in Silverlight.

Member | Description
ErrorToString | Overloaded. Returns the error message that corresponds to a given error number.
Fix | Overloaded. Returns the integer part of a number.
Hex | Overloaded. Returns a string that represents the hexadecimal value of a number.
Int | Overloaded. Returns the integer part of a number.
Str | Returns a String representation of a number.
Val | Overloaded. Returns the numbers that are contained in a string as a numeric value of appropriate type.

Microsoft.VisualBasic.DateAndTime

All members of Microsoft.VisualBasic.DateAndTime are supported in Silverlight. This class includes the members shown in the following table.

Note Note:

Setting the time and date through Visual Basic is not supported in Silverlight.

Member

Description

DateAdd

Overloaded. Returns a Date value that contains a date and time value to which a specified time interval has been added.

DateDiff

Overloaded. Returns a Long value that specifies the number of time intervals between two Date values.

DatePart

Overloaded. Returns an Integer value that contains the specified component of a given Date value.

DateSerial

Returns a Date value that represents a specified year, month, and day, with the time information set to midnight (00:00:00).

DateString

Returns a String value that represents the current date.

Note Note:

The date returned is formatted as MM\-dd\-yyyy.

DateValue

Returns a Date value that contains the date information represented by a string, with the time information set to midnight (00:00:00).

Day

Returns an Integer value from 1 through 31 that represents the day of the month.

Hour

Returns an Integer value from 0 through 23 that represents the hour of the day.

Minute

Returns an Integer value from 0 through 59 that represents the minute of the hour.

Month

Returns an Integer value from 1 through 12 that represents the month of the year.

MonthName

Returns a String value that contains the name of the specified month.

Now

Returns a Date value that contains the current date and time according to the system.

Second

Returns an Integer value from 0 through 59 that represents the second of the minute.

TimeOfDay

Returns a Date value that contains the current time of day according to the system.

Note Note:

Setting the time and date through Visual Basic is not supported in Silverlight.

Timer

Returns a Double value that represents the number of seconds that have elapsed since midnight.

TimeSerial

Returns a Date value that represents a specified hour, minute, and second, with the date information set relative to January 1 of the year 1.

TimeString

Returns a String value that represents the current time of day according to the system.

Note Note:

Setting the time and date through Visual Basic is not supported in Silverlight.

TimeValue

Returns a Date value that contains the time information represented by a string, with the date information set to January 1 of the year 1.

Today

Returns a Date value that contains the current date according to the system.

Note Note:

Setting the time and date through Visual Basic is not supported in Silverlight.

WeekDay

Returns an Integer value that contains a number that represents the day of the week.

WeekDayName

Returns a String value that contains the name of the specified weekday.

Year

Returns an Integer value from 1 through 9999 that represents the year.

Microsoft.VisualBasic.ErrObject

The following table shows the members of Microsoft.VisualBasic.ErrObject that are supported in Silverlight.

Member | Description
Clear | Clears all property settings of the ErrObject
Description | Returns or sets a String expression that contains a descriptive string associated with an error. Read/write.
Erl | Returns an integer that indicates the line number of the last executed statement. Read-only.
GetException | Returns the exception that represents the error that occurred.
Number | Returns or sets a numeric value that specifies an error. Read/write.
Raise | Generates a run-time error. This method can be used instead of the Error statement.

Microsoft.VisualBasic.Globals

All members of Microsoft.VisualBasic.Globals are supported in Silverlight. This class includes the members in the following table.

Member | Description
ScriptEngine | Returns a String that represents the runtime currently being used.
ScriptEngineBuildVersion | Returns an Integer that contains the build version number of the runtime currently being used.
ScriptEngineMajorVersion | Returns an Integer that contains the major version number of the runtime currently being used.
ScriptEngineMinorVersion | Returns an Integer that contains the minor version number of the runtime currently being used.

Microsoft.VisualBasic.HideModuleNameAttribute

The HideModuleNameAttribute is supported in Silverlight.

Microsoft.VisualBasic.Information

The following table shows the members of Microsoft.VisualBasic.Information that are supported in Silverlight.

Member | Description
Err | Contains information about run-time errors.
Erl | Returns an Integer value that indicates the line number of the previously executed statement.
IsArray | Returns a Boolean value that indicates whether a variable points to an array.
IsDate | Returns a Boolean value that indicates whether an expression represents a valid Date value.
IsDBNull | Returns a Boolean value that indicates whether an expression evaluates to the System..::.DBNull class.
IsError | Returns a Boolean value that indicates whether an expression is an exception type.
IsNothing | Returns a Boolean value that indicates whether an expression has no object assigned to it.
IsReference | Returns a Boolean value that indicates whether an expression evaluates to a reference type.
LBound | Returns the lowest available subscript for the indicated dimension of an array.
UBound | Returns the highest available subscript for the indicated dimension of an array.
VarType | Returns an Integer value that contains the data type classification of a variable.

Microsoft.VisualBasic.Interaction

The following table shows the members of Microsoft.VisualBasic.Interaction that are supported in Silverlight.

Member | Description
Choose | Selects and returns a value from a list of arguments.
IIf | Returns one of two objects, depending on the evaluation of an expression.
Partition | Returns a string that represents the calculated range that contains a number.
Switch | Evaluates a list of expressions and returns an Object value that corresponds to the first expression in the list that is True.

Microsoft.VisualBasic.MyGroupCollectionAttribute

All members of Microsoft.VisualBasic.MyGroupCollectionAttribute are supported in Silverlight. This class includes the members shown in the following table.

Member | Description
CreateMethod | This property supports the Visual Basic runtime infrastructure and is not intended to be used directly from your code.
DefaultInstanceAlias | This property supports the Visual Basic runtime infrastructure and is not intended to be used directly from your code.
DisposeMethod | This property supports the Visual Basic runtime infrastructure and is not intended to be used directly from your code.
MyGroupName | This property supports the Visual Basic runtime infrastructure and is not intended to be used directly from your code.

Microsoft.VisualBasic.Strings

The following table shows the members of Microsoft.VisualBasic.Strings that are supported in Silverlight.

Member

Description

Asc

Overloaded. Returns an Integer value that represents the character code corresponding to a character.

Note Note:

In Silverlight, single-byte encoding is assumed.

AscW

Overloaded. Returns an Integer value that represents the Unicode character code corresponding to a character.

Chr

Returns the character associated with the specified character code.

Note Note:

In Silverlight, single-byte encoding is assumed.

ChrW

Returns the character associated with the specified Unicode character code.

Filter

Overloaded. Returns a zero-based array that contains a subset of a String array filtered by specified criteria.

Format

Returns a string formatted according to instructions that are contained in a format String expression.

FormatCurrency

Returns an expression formatted as a currency value. This method uses the currency symbol defined in the system's Control Panel.

FormatDateTime

Returns a string expression that represents a date/time value.

FormatNumber

Returns an expression formatted as a number.

FormatPercent

Returns an expression formatted as a percentage (that is, multiplied by 100) with a trailing percent (%) character.

GetChar

Returns a Char value that represents the character from the specified index in the supplied string.

InStr

Overloaded. Returns an integer that specifies the start position of the first occurrence of one string within another.

InStrRev

Returns the position of the first occurrence of one string within another, starting from the right side of the string.

Join

Overloaded. Returns a string created by joining a number of substrings that are contained in an array.

LCase

Overloaded. Returns a string or character converted to lowercase.

Left

Returns a string that contains a specified number of characters from the left side of a string.

Len

Returns an integer that contains the number of characters in a string.

Note Note:

In Silverlight, Len is not overloaded. Only StringsLen(String) is supported in Silverlight.

LSet

Returns a left-aligned string that contains the specified string adjusted to the specified length.

LTrim

Returns a string that contains a copy of a specified string without leading spaces.

Mid

Overloaded. Returns a string that contains a specified number of characters from a string.

Replace

Returns a string in which a specified substring has been replaced with another substring a specified number of times.

Right

Returns a string that contains a specified number of characters from the right side of a string.

RSet

Returns a right-aligned string that contains the specified string adjusted to the specified length.

RTrim

Returns a string that contains a copy of a specified string without trailing spaces.

Space

Returns a string that consists of the specified number of spaces.

Split

Returns a zero-based, one-dimensional array that contains a specified number.

StrComp

Returns -1, 0, or 1, depending on the result of a string comparison.

StrDup

Overloaded. Returns a string or object that consists of the specified character repeated the specified number of times.

StrReverse

Returns a string in which the character order of a specified string is reversed.

Trim

Returns a string that contains a copy of a specified string without leading or trailing spaces.

UCase

Overloaded. Returns a string or character that contains the specified string converted to uppercase.

Microsoft.VisualBasic.VbMath

All members of Microsoft.VisualBasic.VbMath are supported in Silverlight. This class includes the members shown in the following table.

Member | Description
Randomize | Overloaded. Initializes the random-number generator.
Rnd | Overloaded. Returns a random number of type Single.

Constants and Enumerations

The following table shows the constants and enumerations that are supported in Silverlight.

Constant or enumeration

Description

CallType Enumeration

Indicates the type of procedure that is invoked when you call the CallByName function.

CompareMethod Enumeration

Indicates how to compare strings when you call comparison functions.

Conditional Compilation Constants

Lists predefined constants that are available for conditional compilation.

Note Note:

The constant _MYTYPE is not supported in Silverlight.

DateFormat Enumeration

Indicates how to display dates when you call the FormatDateTime function.

DateInterval Enumeration

Indicates how to determine and format date intervals when you call date-related functions.

FirstDayOfWeek Enumeration

Indicates the first day of the week to use when you call date-related functions.

FirstWeekOfYear Enumeration

Indicates the first week of the year to use when you call date-related functions.

Print and Display Constants

Lists predefined constants that are available for calling print and display functions.

TriState Enumeration

Indicates a Boolean value or whether the default should be used when calling number-formatting functions.

VariantType Enumeration

Indicates the type of a variant object that is returned by the VarType function.

See Also

Concepts

Visual Basic Run-Time Support in Silverlight
Visual Basic Run-Time Members Not Supported in Silverlight


Visual Basic Run-Time Members Not Supported in Silverlight

[image]

Visual Basic Run-Time Members Not Supported in Silverlight
See Also
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Microsoft.VisualBasic namespace provides types and members as part of the Visual Basic run-time library. This topic lists the run-time members that are not supported in Microsoft Silverlight.

Unsupported Namespaces

The following namespaces are not supported in Silverlight.

Microsoft.VisualBasic.ApplicationServices

Microsoft.VisualBasic.ApplicationServices is not supported in Silverlight.

Microsoft.VisualBasic.Devices

Microsoft.VisualBasic.Devices is not supported in Silverlight.

Microsoft.VisualBasic.FileIO

Microsoft.VisualBasic.FileIO is not supported in Silverlight.

Microsoft.VisualBasic.Logging

Microsoft.VisualBasic.Logging is not supported in Silverlight.

Microsoft.VisualBasic.MyServices

Microsoft.VisualBasic.MyServices is not supported in Silverlight.

Microsoft.VisualBasic.MyServices.Internal

Microsoft.VisualBasic.MyServices.Internal is not supported in Silverlight.

Microsoft.VisualBasic.CompilerServices

Microsoft.VisualBasic.CompilerServices supports the .NET Framework infrastructure. There are differences between the Silverlight version of this namespace and the Visual Studio version. These differences are not listed here because this namespace is not intended to be used directly from your code.

Unsupported Types and Enumerations

The following types and enumerations are not supported in Silverlight.

Microsoft.VisualBasic.ComClassAttribute

ComClassAttribute is not supported in Silverlight.

Microsoft.VisualBasic.Conversion

The following member of Conversion is not supported in Silverlight:

  • Oct

Microsoft.VisualBasic.DateAndTime

The following members of DateAndTime are read-only and cannot be set in Silverlight:

  • DateString

  • TimeOfDay

  • TimeString

  • Today

Microsoft.VisualBasic.ErrObject

The following members of ErrObject are not supported in Silverlight:

  • HelpContext

  • HelpFile

  • LastDLLError

  • Source

Microsoft.VisualBasic.FileSystem

FileSystem is not supported in Silverlight.

Microsoft.VisualBasic.Financial

Financial is not supported in Silverlight.

Microsoft.VisualBasic.Information

The following members of Information are not supported in Silverlight:

  • QBColor

  • RGB

  • SystemTypeName

  • TypeName

  • VbTypeName

  • IsNumeric

Microsoft.VisualBasic.Interaction

The following members of Interaction are not supported in Silverlight:

  • AppActivate

  • Beep

  • CallByName

  • Command

  • CreateObject

  • DeleteSetting

  • Environ

  • GetAllSettings

  • GetObject

  • GetSetting

  • InputBox

  • MsgBox

  • SaveSetting

  • Shell

Microsoft.VisualBasic.SpcInfo

SpcInfo is not supported in Silverlight.

Microsoft.VisualBasic.Strings

The following members of Strings are not supported in Silverlight:

  • StrConv

  • Len

    Note Note:

    In Silverlight, Len is not overloaded. Only StringsLen(String) is supported in Silverlight.

Microsoft.VisualBasic.TabInfo

TabInfo is not supported in Silverlight.

Microsoft.VisualBasic.VBFixedArrayAttribute

VBFixedArrayAttribute is not supported in Silverlight.

Microsoft.VisualBasic.VBFixedStringAttribute

VBFixedStringAttribute is not supported in Silverlight.

Unsupported Constants and Enumerations in the Microsoft.VisualBasic Namespace

The following enumerations are not supported in Silverlight:

  • AppWinStyle enumeration

  • AudioPlayMode enumeration

  • DueDate enumeration

  • FileAttribute enumeration

  • MsgBoxResult enumeration

  • MsgBoxStyle enumeration

  • OpenAccess enumeration

  • OpenMode enumeration

  • OpenShare enumeration

  • VbStrConv enumeration

See Also

Concepts

Visual Basic Run-Time Support in Silverlight
Visual Basic Run-Time Members Supported in Silverlight