Overview
Webbrowser
From Silverlight 3, you can create a Silverlight application running outside the browser host environment.Program.
The webbrowser control allows you to display HTML content in this host environment.
You canCodeAdd the webbrowser control. By default, the webbrowser control does not have a size.
Therefore, you must specify the height and width to display the control in the application. When webbrowser is displayed in an application running in the browser, a rectangle with the specified height and width is displayed to replace the control.
You can set the HTML content to be displayed in the webbrowser control in several ways.
CallNavigatetostringMethod and pass a string containing the XAML content you want to display.
SetSourceSet the attribute to a fully qualified URI or relative Uri.
CallNavigateMethod and pass a fully qualified or relative URI to the HTML content you want to display.
Webbrowser. invokescriptMethod
Execute the script function defined in the currently loaded HTML.
Name
Description
Invokescript (string ):Execute the specified script defined in the currently loaded HTML.
Invokescript (string, array <string> []):Use the specified parameters to execute the specified script function defined in the currently loaded HTML.
Webbrowser. loadcompletedEvent
When the top-level navigation is complete and the content is loaded to the webbrowser control, or an error occurs during the loading.
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 >
<! -- HTML content can be displayed in this space.
Source is a page in clientbin of the web. -->
< Webbrowser X: Name = "Web" Source = "/Script-page.htm" Margin = "15" />
</ Grid >
CS code:
Public Mainpage ()
{
Initializecomponent ();
// When the top-level navigation is complete and the content is loaded to the webbrowser control, or an error occurs during the loading.
Web. loadcompleted + =
New Loadcompletedeventhandler (web_loadcompleted );
}
Void Web_loadcompleted ( Object Sender, navigationeventargs E)
{
// Execute the script function defined in the currently loaded HTML.
// The JavaScript method sayhello () without Parameters ()
Web. invokescript ( " Sayhello " );
// There is a parameter in the JavaScript method greetme (name)
Web. invokescript ( " Greetme " , " 'Silverlight' " );
}
HTML code:
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Title > </ Title >
< Script Language = "JavaScript" >
// Add content for div1
// A parameter method
Function Greetme (name ){
Div1.innerhtml + = " <P> hello! " + Name + " </P> " ;
}
// Method without Parameters
Function Sayhello (){
Div1.innerhtml + = " <P> hello! </P> " ;
}
</ Script >
</ Head >
< Body >
Hello world! < BR />
< Div ID = "Div1" >
</ Div >
</ Body >
</ Html >
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.