Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Silverlight V1.1 - Changing the XAML Page
Mike Taulty's Blog

Mike's Badges

Follow on Twitter
View mike's profile on slideshare
Add to Technorati Favorites
CW Blog Awards

When your Silverlight control loads, it loads up some XAML. It's most likely that this comes from a file specified by the source parameter. For instance;

function createSilverlight()
{
    Sys.Silverlight.createObjectEx({
        source: "Page1.xaml",
        parentElement: document.getElementById("SilverlightControlHost"),
        id: "SilverlightControl",
        properties: {
            width: "100%",
            height: "100%",
            version: "0.95",
            enableHtmlAccess: true
        },
        events: {}
    });
}

It might be that at some later point you want to switch from Page1.xaml to Page2.xaml in order to avoid having to put everything into a single XAML file.

You can do this but (I'm very reliably informed) not from managed code right now and, furthermore, you can't even initiate the sequence from managed code. If you try it from managed code (using the HtmlObject object) then you'll get an error saying something like "No, you can't do that right now".

So, you need to do it from Javascript and just change the source property;

function OnChangePage()
{
    document.getElementById('SilverlightControl').source = "Page2.xaml";
}

what did I mean by "initiate the sequence from managed code" - you need to make sure that the page switch comes from a "purely" Javascript place. That is, if your Javascript function to switch pages is called as a result of an event in the managed world then it'll fail (crash is what I'm told).

In my case, I wanted to change pages when an animation completed so that was a scenario where it was easy enough to add a purely Javascript handler to and perform the page-switch there.


Posted Wed, Jul 25 2007 5:18 PM by mtaulty
(C) Mike Taulty, 2009. All rights reserved. The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems