tags:

views:

25

answers:

3

Hi,

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 would 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?

Kind Regards

James

A: 

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.

Enough already
A: 

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

James
I think it's much easier to check QueryString in SL rather than to modify your html - you could just use plain html pages without the need of ASP.NET, PHP or whatever.
VyvIT
A: 

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

VyvIT