I'm c开发者_JAVA技巧onsidering a scenario where I'd have a Silverlight 3 (or greater) application, which would utilize the SL Navigation framework.
Let us assume (for simplicity's sake) that it would be a simple forum. In my application I'd have a a page named Forums.xaml
Normally when I'd navigate to the said page the URL in the browser would change and the trailing string would match the page's name.
Normally it is possible to access a forum post by supplying the post's id in the url (to navigate directly to the forum post). Is such a thing possible in Silverlight?
As always, it depends on what specifically you're after. If you just want to pull the query string value when you've landed on the page, use the dictionary supplied by NavigationContext.QueryString:
Assuming the page was called with the following Url:
mainFrame.Navigate(new Uri("/Page1.xaml?Param=value", UriKind.Relative));
The resulting OnNavigatedTo override might look like this:
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey("Param"))
{
paramText.Text = NavigationContext.QueryString["Param"];
}
}
Then it is up to you to adjust content on "Page1" based on the incoming parameter.
Now if you want to use Uri Mapping and clean up your Uri a bit, you can declare a UriMapper and hand it to your Navigation Frame, and use it to change your "clean" url into one that has a query string.
<Navigation:UriMapper x:Key="PageMapper">
<Navigation:UriMapping Uri="/Things/{value}" MappedUri="/Page1.xaml?Param={value}"/>
</Navigation:UriMapper>
When called with:
mainFrame.Navigate(new Uri("/Things/newValue", UriKind.Relative));
will work with the same call listed above in OnNavigatedTo, with "newValue" passed as the query string (in your case, the Id) and the following appearing in the address bar:
'http://localhost:1877/SilverlightApplication3TestPage.aspx#/Things/newValue
精彩评论