Silverlight导航框架-regex之类的uri映射配置问题

发布于 2024-12-05 07:48:20 字数 393 浏览 2 评论 0原文

我对我的应用程序的 URI 结构有一个想法,因此如果它以 #Home 结尾,它将导航到主框架。然而,如果它以类似 #{\d\d\d} (此处为 3 位数字的正则表达式)结尾,它将导航到 #Home 并将这 3 位数字传递为一个参数。

我认为导航框架不支持大括号中 {parameters} 的正则表达式,并且通常需要 URI 映射中的 #Home/{id} 之类的内容。如果我只是做 #{id} 映射 #Home ,甚至 #AnotherPage 也会陷入其中。

如果我想坚持我的 URI 计划,我怎样才能实现这一点,最简单的方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦笑流年记忆 2024-12-12 07:48:20

也许您可以实现自定义 urimapper 来实现此目的。以此为例:Silverlight 3 中区分大小写的 UriMapper 问题

..或者

您可以尝试类似

然后,在 Home.xaml.cs 中,您应该能够执行以下操作:

  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
   } 

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
   } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文