2011-09-18 55 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

剛試過那個正則表達式,它不起作用。 –