开发者

Navigating Silverlight pages from HTML

开发者 https://www.devze.com 2023-01-13 09:35 出处:网络
I am developing a website that contains a number of \"forms\" for entering data, etc, and I plan on using Silverlight and RIA Services for managing the data within these forms. The rest of the site wi

I am developing a website that contains a number of "forms" for entering data, etc, and I plan on using Silverlight and RIA Services for managing the data within these forms. The rest of the site will be normal HTML/CSS/JavaScript.

The plan was to create a single Silverlight control with many pages and each page would represent a single form. A HTML page would display this control, but would display a specific page within the Silverlight control.

So, my questions are:

  1. When embedding a Silverlight control within a HTML page how wo开发者_JAVA技巧uld have the control automatically navigate to a specific page?

  2. After loading a HTML page, and display the Silverlight control, would it be possible to have some JavaScript tell the Silverlight control to navigate to another page?


1 - Silverlight uses URL bookmarks on the end of the URL to emulate navigation.

e.g. http://somesite.com/somepage.aspx#formname

You can also override the default behaviour of the navigation so that it can do cool things like use the bookmark parameter to dynamically specify the name of the Silverlight form you want to show.

2 - You would only need to ensure the bookmark part of your site URLs contain something the Silverlight application can interpret.

Lookup the INavigationContentLoader interface for examples of overriding the navigation with custom behaviour.I found a few articles on the subject quite easily. Try this one.


After a bit of searching I found that the "object" tag that defines the Silverlight control in HTML can have a "initParams" element within it.

So, my thought is each page that I create will only ever have one "form" therefore in the "object" tag I just set "initParams" to define which page the Silverlight control should set as the "RootVisual".

When the control loads the Application_Startup will look at the "initParams" and use that to determine what page it needs to create and assign it to the RootVisual property of the application.

James


1) One of the solutions (not the best one) would be like this:

private void Application_Startup(object sender, StartupEventArgs e)
    {

        var page = HtmlPage.Document.QueryString["Page"];
        RootVisual = GetPage(page);

    }

    private UIElement GetPage(string page)
    {
        switch (page)
        {
            case "page1": return new Page1();
            case "page2": return new Page2();
            default: return new PageNotFound();
        }
    }

2) If you want to interact Silverlight control with HTML (JavaScript), then this is called a 'Silverlight HTML bridge':

HTML Bridge: Interaction Between HTML and Managed Code

0

精彩评论

暂无评论...
验证码 换一张
取 消