Example of XBAP carrying Silverlight

Source: Internet
Author: User
Tags silverlight

Microsoft MSDN:

Http://msdn.microsoft.com/zh-cn/library/cc656722 (v = vs.90). aspx

 

This example demonstrates the following:

  • How to host Silverlight-based applications in a XAML browser application (XBAP.

  • Communication between host XBAP and Silverlight-based hosted applications.

Download sample

Carrying Silverlight-based applications in XBAP

You can use the WebBrowser control to host Silverlight-based applications in XBAP. The content of XBAP Page contains the WebBrowser control. The source URI of this control can identify HTML pages that carry Silverlight-based applications. The HTML page uses the Silverlight plug-in control to host Silverlight-based applications.

This section describes the High-level architecture of a Silverlight-based application in XBAP.

Communication from XBAP to Silverlight-based applications

The host XBAP can communicate with the Silverlight-based Host application using the script method. The script method here is implemented by carrying the HTML page of The Silverlight-based application. XBAP uses the InvokeScript method to call the script method. The script method then calls the method implemented by the Scriptable object. The object is made public by a Silverlight-based application, and its script call can be implemented through the Content attribute of the Silverlight plug-in control.

This section describes the High-Level Architecture of Silverlight-based applications in XBAP and the key technologies used to call the method for transmitting methods from the host xbap to the Silverlight-based Host application.

To use the WebBrowser control to call the script method, see the WebBrowser control example. For more information about implementing Silverlight-based applications (used to publish Scriptable objects), see Walkthrough: Calling Managed Code from JavaScript (Walkthrough: Calling Managed Code from JavaScript ). For more information about how to develop Silverlight-based applications, see Getting Started with Silverlight ).

Communication from Silverlight-based applications to XBAP

The Silverlight-based Host application can communicate with the host XBAP by using the script method. The script method here is implemented by carrying the HTML page of The Silverlight-based application. Silverlight-based applications use the Invoke method of the HtmlWindow class (from the System. Windows. Browser namespace) to call the script method. A Silverlight-based application obtains a reference to a Window (represented by the HtmlWindow class) from the Window attribute of the HtmlPage class (also located in the System. Windows. Browser namespace. The script method then calls the method implemented by an object that can write scripts. The object is made public from XBAP through the ObjectForScripting attribute, and its script call can be made public through the window object (published by the host browser).

This section describes the High-level architecture of the Silverlight-based application in XBAP, and the key technologies used to call the Silverlight-based Host application to the host XBAP propagation method.

To call the script method from a Silverlight-based application, see Walkthrough: Calling JavaScript from Managed Code (Walkthrough: Calling JavaScript from Managed Code ). For more information about publishing Scriptable objects from XBAP, see the WebBrowser control example and ObjectForScripting.

Configuration example

This example consists of a solution (XBAPHostingSilverlightSample) and two projects:

  1. XBAP Project (WPFBrowserApplication) is used to host Silverlight-based applications.

  2. Silverlight-based application project (SilverlightApplication ).

SilverlightApplication is generated after WPFBrowserApplication. It includes a post-generation step. The generated Silverlight-based application silverlightspplication. xap is copied to the output folder of the WPFBrowserApplication project: \ bin \ debug.

You must use the following steps to configure the example so that it directs to the virtual directory of the WPFBrowserApplication project Output Folder (\ bin \ debug) from localhost to run:

  1. Select "Internet Information Service (IIS) manager" from "start" | "Administrative Tools ".

  2. Select "website" | "default website ".

  3. Right-click "default website", select "add virtual directory", and then

    1. Set "alias" to "WPFBrowserApplication ".

    2. Set "physical path" to the output folder of the wpfbrowserapplication project.

  4. Click "OK" to create a virtual directory.

Running example

To run the example, navigate to the following URL:

Http: // localhost/WPFBrowserApplication. xbap

Best practices

This example demonstrates specific features of the Windows Presentation Foundation and does not follow best practices for application development. For a comprehensive introduction to best practices for Windows Presentation Foundation (WPF) and Microsoft. NET Framework application development, see the following topics:

Auxiliary functions-optimal solution for auxiliary functions

Localization-WPF overview of globalization and Localization

Performance-optimizes the performance of WPF applications

Security-Windows Presentation Foundation Security

Generation example

  • Install the Windows software development kit (SDK) and open its generate Environment command window. On the Start Menu, point to all programs and Microsoft Windows SDK, and then click CMD Shell ".

  • Download the example (usually in the software development kit (SDK) Documentation) to your hard disk.

  • To generate an example from the generate Environment command window, go to the source directory of the example. At the command prompt, type MSBUILD.

  • To generate an example in Microsoft Visual Studio, load the sample solution or project file, and press Ctrl + Shift + B.

Running example

  • To run compiled examples in the Command window of the Generation Environment, run the. exe file in the Bin \ Debug or Bin \ Release folder in the sample source code folder.

  • To debug compiled examples in Visual Studio, press F5.

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.