开发者

Silverlight navigation frame - regex like uri mapping configuration problem

开发者 https://www.devze.com 2023-04-05 21:13 出处:网络
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 nav

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
   } 
0

精彩评论

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

关注公众号