开发者

Passing Query string to silverlight

开发者 https://www.devze.com 2023-02-11 16:40 出处:网络
I have a silverlight project that has many xam开发者_运维技巧l pages.i have an external website that will call the silverlight website so e.g. http://mysilverlightproject:1230.com?queryString1=Page1.x

I have a silverlight project that has many xam开发者_运维技巧l pages. i have an external website that will call the silverlight website so e.g. http://mysilverlightproject:1230.com?queryString1=Page1.xaml.

i want to change the page by passing the values from query string.

is it possible to change the main xaml page to be another page from the query string?

Thanks


string val = string.Empty;
if (HtmlPage.Document.QueryString.ContainsKey(”foo”))
{val = HtmlPage.Document.QueryString["foo"];}


As far as I know you can't change Main page after it is assigned from App class. But you can use Navigation framework and navigate to needed page. In this case you also will be able to use browsers back/forward button.
This post is about navigating from code behind.


Take a look at how a Silverlight Navigation Application works. It will give you the functionality you request.


you can pass pageId to SL application by initparams specific to different URLs and load required page inside SL application instead of default start page

Init params are placed in html and are passed inside SL app, like the following

<param name="InitParameters" value="queryString=Page10" />

Inside you can use SilverlightHost class to get them

        SilverlightHost host = new SilverlightHost();
        if (host.InitParams.Count > 0)
        {
            foreach (var c in host.InitParams)
            {
                if(c.Key == "queryString")
                  RedirectToUIPage(c.Value) // your method
            }
        }
0

精彩评论

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