chamara
chamara

Reputation: 12709

Silverlight page navigation

I'm using silverlight content within a aspx page.i have created silverlight page is in a separate silverlight project and i have added that project to my normal asp.net application ClientBin.i need to redirect to a aspx page on my asp.net project from a silverlight page button click.how can i achive this?

Upvotes: 0

Views: 495

Answers (1)

Neel Edwards
Neel Edwards

Reputation: 308

I think you have one of two options. In your view model for that silverlight control, during the initialization, Bind the navigate URI for a hyperlink button to the desired URI you want to navigate to. Option 2 (a lot smoother): On the click method, Invoke a javascript method on the page that hosts the silverlight object. That method would then do some sort of smooth jquery transition or just a simple navigation for you.
Option 1: <HyperlinkButton NavigateUri="{Binding DesiredURL}" TargetName="_blank" />

For option 2, remember to include:

using System.Windows.Browser;

Option 2:

        public void OnFancyNavigate(string _destination)
    {
        //call the browser method/jquery method (I used constants to centralize the names of the respective browser methods
        try
        {
            HtmlWindow window = HtmlPage.Window;
            window.Invoke(Constants.TBrowserMethods.BM_FANCYNAVIGATE, new object[] { _destination});
        }
        catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
    }

Lastly, define the javascript method in the aspx/html/.js file that hosts the xap content:

function fancyNavigate(_destination) {
//some fancy jquery or just the traditional document.location change here

}

C# will locate the javascript method when invoked from your code, and you should be good to go

Upvotes: 1

Related Questions