New Feature: Playlist Center! Pick a topic and let our playlists guide the way—like a learning mixtape.

Start learning with our library of video tutorials taught by experts. Get started

Silverlight 5 Essential Training
Illustration by

Hosting HTML content in Silverlight applications


From:

Silverlight 5 Essential Training

with Walt Ritscher

Video: Hosting HTML content in Silverlight applications

Silverlight has always worked within an HTML page. As you probably know, the Silverlight host control is embedded in an HTML or ASP.NET page and loaded into the Silverlight runtime when the page loads. But within the Silverlight application itself, there has never been the ability to embed HTML. This is annoying, for several reasons. First you're likely to have lots of assets already in HTML. Wouldn't it be nice to be able to reuse them in sections of your Silverlight app? Two, without HTML it is harder to create a searchable site, and there is no easy way to embed advertisements within your content.
Expand all | Collapse all
  1. 1m 41s
    1. Welcome
      53s
    2. Using the exercise files
      48s
  2. 35m 0s
    1. Overview of Silverlight
      3m 29s
    2. Setting up a developer computer
      2m 46s
    3. Installing the Silverlight Toolkit
      2m 21s
    4. Exploring the toolkit samples
      2m 35s
    5. Using Visual Studio 2010 to create a Silverlight project
      5m 10s
    6. Using Expression Blend to create a Silverlight project
      3m 13s
    7. Getting to know the Visual Studio interface
      8m 15s
    8. Working in the Expression Blend interface
      7m 11s
  3. 29m 46s
    1. Understanding the Visual Studio project structure
      3m 38s
    2. Creating a Silverlight page
      3m 17s
    3. Compiling your first application
      5m 0s
    4. Using other assemblies in an application
      5m 45s
    5. Deploying a Silverlight application
      3m 43s
    6. Understanding the startup process for an application
      3m 13s
    7. Understanding how users get Silverlight on their computers
      5m 10s
  4. 16m 59s
    1. Exploring the relationship between XAML and .NET
      3m 57s
    2. Using C#
      7m 16s
    3. Exploring the code-behind file
      5m 46s
  5. 43m 22s
    1. Working with XAML elements and Property attributes
      4m 56s
    2. Investigating XAML namespaces
      7m 31s
    3. Converting XAML properties with TypeConverters
      5m 1s
    4. Working with Property elements
      4m 24s
    5. Assigning runtime data with XAML markup extensions
      4m 21s
    6. Digging into the dependency property system
      6m 12s
    7. Creating a custom dependency property
      4m 42s
    8. Understanding attached properties
      6m 15s
  6. 9m 35s
    1. Debugging your code
      5m 17s
    2. Special Silverlight debugging techniques
      4m 18s
  7. 36m 0s
    1. Understanding layout
      4m 55s
    2. Using DockPanel and WrapPanel
      4m 2s
    3. Exploring sophisticated layouts with the Grid
      6m 40s
    4. Absolute positioning with the Canvas panel
      5m 20s
    5. Scrolling content with the ScrollViewer
      3m 28s
    6. Adjusting content alignment, margins, and sizing
      5m 6s
    7. Using the TabControl
      2m 17s
    8. Manipulating elements with transforms
      4m 12s
  8. 20m 32s
    1. Painting the user interface (UI) with SolidColorBrush
      6m 7s
    2. Getting colorful with gradient brushes
      3m 15s
    3. Decorating elements with ImageBrush
      4m 56s
    4. Creating effects with VideoBrush
      6m 14s
  9. 25m 42s
    1. Understanding routed events
      3m 12s
    2. Wiring up event handlers in Silverlight
      6m 4s
    3. Understanding event bubbling
      4m 39s
    4. Exploring mouse events
      7m 43s
    5. Exploring keyboard events
      4m 4s
  10. 32m 31s
    1. Displaying text on the screen
      3m 24s
    2. Gathering text input from the user
      5m 30s
    3. Showing complex text with RichTextBox
      6m 7s
    4. Understanding text overflow and text linking
      3m 14s
    5. Searching content with the AutoComplete type-ahead control
      6m 45s
    6. Using and embedding Silverlight fonts
      7m 31s
  11. 26m 47s
    1. Understanding content controls
      5m 7s
    2. Understanding button controls
      6m 16s
    3. Using the BusyIndicator
      4m 40s
    4. Showing tooltips
      4m 34s
    5. Changing content size with ViewBox
      1m 39s
    6. Exploring more controls
      4m 31s
  12. 55m 36s
    1. Connecting elements with binding
      9m 54s
    2. Using business data in a binding
      9m 21s
    3. Listing data with ItemsControls
      6m 39s
    4. Digging into the DataGrid
      8m 28s
    5. Using the DataForm
      3m 49s
    6. Storing data on the client
      7m 10s
    7. Debugging XAML bindings
      5m 41s
    8. Charting data
      4m 34s
  13. 24m 36s
    1. Creating an Out-of-Browser (OOB) application
      6m 16s
    2. Controlling aspects of an OOB application
      2m 49s
    3. Alerting the user with notification windows
      7m 13s
    4. Hosting HTML content in Silverlight applications
      8m 18s
  14. 30m 2s
    1. Exploring Silverlight trust levels
      3m 51s
    2. Creating an elevated trust application
      5m 57s
    3. Reaping the benefits of XAP signing
      6m 5s
    4. Making cross-domain calls
      5m 1s
    5. Getting started with COM Interop using the Speech API
      4m 21s
    6. Using COM Interop to interact with Microsoft Office
      4m 47s
  15. 16m 33s
    1. Showing child windows
      3m 48s
    2. Using a child window as a dialog window
      5m 7s
    3. Creating native windows
      2m 53s
    4. Maximizing a window with full screen mode
      4m 45s
  16. 13m 20s
    1. Dynamically loading UI content with user controls
      4m 46s
    2. Using the Navigation Framework
      8m 34s
  17. 9m 28s
    1. Using resource files
      3m 53s
    2. Using images in an application
      5m 35s
  18. 16m 32s
    1. Playing audio
      4m 27s
    2. Playing sound effects
      5m 4s
    3. Viewing video content with MediaElement
      4m 58s
    4. Changing video playback speed with TrickPlay
      2m 3s
  19. 14m 40s
    1. Capturing video with a web camera
      4m 16s
    2. Working with a microphone
      3m 47s
    3. Creating print output
      6m 37s
  20. 22m 35s
    1. Understanding Silverlight animations
      4m 35s
    2. Creating animations
      7m 52s
    3. Controlling animations
      4m 18s
    4. Simulating physics with animation easings
      5m 50s
  21. 27m 47s
    1. Placing XAML resources within a FrameworkElement
      6m 47s
    2. Centralizing settings in styles
      4m 8s
    3. Creating an alternate control UI with ControlTemplates
      6m 29s
    4. Dressing up your data with DataTemplates
      4m 33s
    5. Explaining the VisualStateManager: a simple way to manage control states
      5m 50s
  22. 10m 55s
    1. Handling global errors in a Silverlight application
      5m 46s
    2. Showing an application loading screen
      5m 9s
  23. 10m 48s
    1. Integrating with XNA
      7m 40s
    2. Exploring data analysis with PivotViewer
      3m 8s
  24. 1m 6s
    1. Goodbye
      1m 6s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Silverlight 5 Essential Training
8h 51m Beginner Mar 27, 2012

Viewers: in countries Watching now:

Microsoft Silverlight 5 is a rich application framework for creating high-performance, cross-platform desktop and mobile applications. In this course, author Walt Ritscher demonstrates how to build a variety of applications in Silverlight, with particular focus on building compelling business applications and delivering premium video and audio content. Developers will work with the C# programming language and Visual Studio Professional, as well as Expression Blend, a tool that simplifies creation of the interactive user interfaces expected in modern-day applications.

Topics include:
  • Installing the toolkit and setting up the development environment
  • Using Expression Blend vs. Visual Studio 2010
  • Creating a Silverlight page
  • Compiling an application
  • Exploring the relationship between XAML and .NET
  • Using C#
  • Working with XAML
  • Digging into the Dependency Property System
  • Deploying and debugging code
  • Creating sophisticated layouts with panel elements
  • Managing Visual State with Visual State Manager
  • Transforming the user interface (UI) with templates
  • Understanding the event model
  • Working with text
  • Using business data in a binding
  • Creating an out-of-browser (OOB) application
  • Exploring trust levels
  • Playing audio and video
  • Handling errors
  • Exploring animations
  • Working with application windows
  • Integration with XNA
Subject:
Developer
Software:
Silverlight Visual Studio
Author:
Walt Ritscher

Hosting HTML content in Silverlight applications

Silverlight has always worked within an HTML page. As you probably know, the Silverlight host control is embedded in an HTML or ASP.NET page and loaded into the Silverlight runtime when the page loads. But within the Silverlight application itself, there has never been the ability to embed HTML. This is annoying, for several reasons. First you're likely to have lots of assets already in HTML. Wouldn't it be nice to be able to reuse them in sections of your Silverlight app? Two, without HTML it is harder to create a searchable site, and there is no easy way to embed advertisements within your content.

Another prime developer request from Microsoft is the ability to embed Flash content within a Silverlight app. I'm happy to tell you that Silverlight 4 supports HTML embedding. The one caveat to this is that your Silverlight application must be an out-of-browser app. There are two ways to show HTML content. If you just want to host an instance of the browser in your app, choose the webBrowser control. If you'd like to use the HTML to paint on the screen, use the webBrowserBrush instead.

Why have a webBrowserBrush? Because you cannot apply transforms to the webBrowser Control itself. It's just a wrapper for the browser window. But you can create a snapshot of the Bbrowser content, load it into a brush, and then manipulate that on screen. Let's take a look in Visual Studio. I have loaded the hosting HTML content into Visual Studio, and I'm going to open the NavigateToStringPage. This is currently my start page, and this is currently set to be an out-of-browser application.

This white area on the bottom of the screen is the out-of-browser control, the webBrowser control. And as you can see, it's giving me a warning saying HTML is enabled only an Out-of-Browser mode. So if I were to run this application right now and look at this page and I wasn't in Out-of-Browser mode, this would be the message that I would see. When I click on this button here, I'm going to load some static HTML. Let's take a look at that by pressing F7 to look at a code behind. Here it is. When I click the button, I am going to call the NavigateToString method, which is a simple way to provide any arbitrary HTML string that I want.

Here I've got a little HTML snippet saying Hello World. Another way of getting the content would be to go out to the Internet and find a site that has content that I want to stream into my application. That's what I'm doing in this button down here, on line 27. I'm checking to see if I'm running out of browser. If I am, I am going to create a webClient. Now the webClient class is a simple way to ask for a resource on a web server. I am going to create this request and I am going to say that when the request is done running I want to have a callback function called pageRequest_DownloadStringCompleted, right.

I've set up this callback. Then I am going to call DownloadStringAsync, which creates a worker thread, goes out and gets the content, and then returns it through this function down here. As you can see, I'm making a request to my web site, my blog, and then I'm going to take that resulting value and send it to the NavigateToString method. Simple, right? Let's see if it runs. Press F5 to debug, click on this button that says Add HTML content. And there you see my simple HTML snippet, and when I click over here, I get a script error.

I am getting this from Internet Explorer. And then once that script error is gone, I see my blog web site. There it is. Let me show you how to embed a YouTube video inside a browser control. That's this page right here, ShowYouTubePage. I need to make that my startup page, so I am going to go to App.xaml.cs and change this line of code here. I am going to change that to ShowYouTube. There you go, okay. Now this is pretty simple to do. In this ShowYouTubePage in the Page_Loaded event, I just went out and I grabbed an object tag here and placed that in the NavigateToString.

Recently, I went to the YouTube web site, found a video I liked, and copied the embed HTML and placed it here. And there is our video. This is from the lynda.com archives. I am going to click on here to see if it plays correctly. (video playing) Good! Again, that was very simple to set up. The last demo, I am going to show you how to use the webBrowserBrush.

I'm going to paint a reflection of that same video I just showed you on the bottom half of the page. That's down here in the webBrowserBrushPage.xaml, and I also need to change my startup. So I am going to go to App.xaml.cs and change this here to be webBrowserBrushPage, okay. And then return over here to take a look at what I've done. Again I have a webBrowser control and then down below I have a rectangle and I have a mouse procedure setup there. I don't think I am using that in this demo, but I set it up anyway.

And then I've created a PlaneProjection. Now PlaneProjection, what that allow me to do is manipulate this element in 2D space, so I can make it look like I'm spinning it around an axis. I've created this PlaneProjection. I've also created an animation to spin that part of the screen. I'll show you that in a minute. Here is my RenderTransform that's taking that Rectangle and pushing it down to the bottom of the screen and turning it upside down. ScaleY="-1" is what turns it upside down on this CompositeTransform.

And then here is the key part. The Fill value from this Rectangle, which is normally things like, you know, solid color brushes, I'm telling it to use my webBrowserBrush. And then I pass in the source name, which is the other webBrowser Control. So again, what's going to happen is all the pixels that are rendering inside this browser control will be re-rendered down here in this brush, and then the brush is going to be applied to this rectangle. Now, the webBrowserBrush doesn't automatically refresh itself. That's why I had this code up here for rectangle_MouseLeftbuttonUp. So I could click on that item and say refresh, refresh, refresh.

I decided that was a bit silly to do it that way, so instead, what I did is I created a timer. I'll press F7 to show you that. I create an instance of the DispatcherTimer and set that to 100 milliseconds and then every time the timer ticks down here, I call the wbBrush.Redraw. Time to see what it looks like. Press F5. There is my reflection. You can see it down on the bottom of the screen. It's upside down. When I run the video you can see that I am getting the reflected value in the bottom half of the screen.

(video playing) (Male speaker: I used to like to show them.) It's probably better if I shut that off so you can hear what I am saying. And now when I click on this bottom half of this screen, that's my rectangle, I've got that perspective transform happening down there, so you can see I can spin it around. Run the video again. (video playing) Stop in a different place and show that I can manipulate that. If I didn't have to talk over the running video, I could run the video and do that pivot animation at the same time. There are still some limitations with HTML Silverlight, but this is a good start.

The biggest limitation being that you have to run in out-of-browser. But there is a solution for that too. Remember, that you can interact with the browser page from the Silverlight application.

Find answers to the most frequently asked questions about Silverlight 5 Essential Training.


Expand all | Collapse all
please wait ...
Q: I'm trying to access a Silverlight 3D application template, [cid:image001.png@01CD0E7D.3E07ECA0]. I have already installed the Silverlight 5 SDK and my Visual Studio 2010 is professional. Could you please help me?
A: You must install XNA Studio in order to use the new Silverlight 3D templates. Otherwise the new templates will not show up. Download it at http://www.microsoft.com/download/en/details.aspx?id=23714.

For other Silverlight downloads (the toolkit, developer runtime, etc.), see http://www.silverlight.net/downloads.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Silverlight 5 Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.