Silverlight browser interaction: Use the Silverlight program to display HTML page code (with source code)

Source: Internet
Author: User

Overview

Webbrowser.NavigatetostringMethod

Displays the specified HTML content.

TextThe parameters should be set to HTML format.TextParameters can also contain JavaScript. If HTML contains JavaScript Functions, you can useInvokescriptFrom the managedCodeCall this type of function. Do not useNavigatetostringDisplays untrusted HTML content.

Effect:

XAML code:

<  Grid  X: Name  = "Layoutroot"  >  
< Grid. Background >
< Lineargradientbrush Startpoint = "0, 0" Endpoint = "0, 1" >
< Gradientstop Color = "# Ff0055dd" Offset = "0" />
< Gradientstop Color = "# Ff00ddff" Offset = "1" />
</ Lineargradientbrush >
</ Grid. Background >

< Webbrowser X: Name = "Web" Margin = "15" />
</ Grid >

CS code:

   Public  Mainpage ()
{
Initializecomponent ();

Loaded + = New Routedeventhandler (mainpage_loaded );
}

Void Mainpage_loaded ( Object Sender, routedeventargs E)
{
// Use stringbuilder to create an HTML content page
VaR html = New Stringbuilder ();
Html. append ( " <HTML> " );
Html. append ( " <HTML> " );
Html. append ( " <Body style = 'font-family: Arial; font-size: 20pt '> " );
Html. append ( " <Div style = 'color: Blue '> " );
Html. append ( " This is the first Div " );
Html. append ( " </Div> " );
Html. append ( " <Div style = 'color: Orange '> " );
Html. append ( " This is the second Div. " );
Html. append ( " </Div> " );
Html. append ( " <HTML> " );
Html. append ( " </Body> " );


// Webbrowser. navigatetostring Method
// Displays the specified HTML content.
// The text parameter should be set to HTML format. The text parameter can also contain JavaScript.
// If HTML contains JavaScript Functions, you can use the invokescript method to call these functions from managed code.
// For security reasons, it is best not to use navigatetostring to display untrusted HTML content.
Web. navigatetostring (html. tostring ());
}

Success !!!

Source code download

author: memories of lost youth
Source: http://www.cnblogs.com/lukun/
copyright of this Article It is shared by the author and the blog site. You are welcome to repost it, but this statement must be kept without the author's consent, and in the Article page obvious position to give the original connection, if there is a problem, you can contact me through the http://www.cnblogs.com/lukun/ , thank you very much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.