2011-09-18 59 views
0

我有我的应用程序的URI结构的想法,所以如果它结束与让我们说#Home它将导航到主框架。但是,如果以#{\d\d\d}(这里是3位数字的正则表达式)结尾,它将导航到#Home并将这3位数字作为参数传递。Silverlight导航框架 - 像uri映射配置问题的正则表达式

我不认为导航框架在大括号中支持{parameters}的正则表达式,它通常在URI映射中期望类似#Home/{id}之类的东西。如果我只是做#{id}映射#Home甚至#AnotherPage也将被捕获。

如果我想坚持我对URI的计划,那么最简单的方法是什么?

回答

0

也许你可以实现一个自定义的urimapper来实现这一点。检查了这一点作为一个例子:Case sensitive UriMapper issue in Silverlight 3

..或

你可以尝试像

<uriMapper:UriMapping Uri="/Views/{myVar}Home" MappedUri="/Views/MainFrame.xaml"/>

<uriMapper:UriMapping Uri="/Views/{myVar}" MappedUri="/Views/Home.xaml?myVar={myVar}"/>

然后,在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 
    } 
+0

我想这可能是它,如果没有其他的方式 –

+0

在那个线程中嗯有人说它使用正则表达式,这是正确的吗?这不应该有助于解决我的问题,如果这是真的吗? –

+0

刚试过那个正则表达式,它不起作用。 –