Silverlight navigation frame - regex like uri mapping configuration problem
I have an idea of URI structure for my app so if it ends with lets say #Home
it will navigate to main frame. If however it ends with something like #{\d\d\d}
(regex for 3 digits here) , it will navigate to #Home
and pass those 3 digits as a parameter.
I don't think navigation framework supports regexes for {parameters}
in curly brackets and it generally 开发者_运维技巧expects something like #Home/{id}
in URI mapping. and if i simply do #{id}
mapping #Home
and even #AnotherPage
will be caught into that too.
If I want to stick to my plan for URI how could I achieve that, the simplest way?
Maybe you could implement a custom urimapper to achieve this. Check this out as an example: Case sensitive UriMapper issue in Silverlight 3
..or
You could try something like
<uriMapper:UriMapping Uri="/Views/{myVar}Home" MappedUri="/Views/MainFrame.xaml"/>
<uriMapper:UriMapping Uri="/Views/{myVar}" MappedUri="/Views/Home.xaml?myVar={myVar}"/>
then, in Home.xaml.cs, you should be able to do the following:
this.Loaded += Home_Loaded;
...
public void Home_Loaded(object sender, RoutedEventArgs e)
{
if (this.NavigationContext.QueryString.ContainsKey("myVar"))
var v = this.NavigationContext.QueryString["myVar"];
//Now examine v. If it is in the correct format \d\d\d then continue.
//Else...redirect or throw exception
}
精彩评论