2010-11-10 93 views
23

在Windows Phone 7的Silverlight應用程序調用我使用WP7:將參數傳遞到新頁面?

NavigationService.Navigate(new Uri("/View/SecondPage.xaml", UriKind.Relative)); 

現在我想參數傳遞給新的一頁新的一頁。我明白了一個簡單的參數,可以使用通過:

NavigationService.Navigate(new Uri("/View/TilgungsratePage.xaml?id=4711", UriKind.Relative)); 

,並在使用

protected override void OnNavigatedTo(Microsoft.Phone.Navigation.PhoneNavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    String id = NavigationContext.QueryString["id"]; 
} 

對於簡單的參數,這是確定新的頁面讀取,但我怎麼通過一個列表?
複雜的物體?
除了簡單的值之外什麼都沒有?

+0

看看這篇文章,以及: WP7 Master - 具有存儲庫模式的詳細信息導航](http://windowsphonegeek.com/articles/WP7-Master---Detail-Navigation-with-Repository-Pattern) – 2012-06-13 15:12:29

+1

查看此鏈接的最後一個方法:http:// www.c-sharpcorner.com/UploadFile/deepak.sharma00/different-ways-of-passing-values-between-windo ws-phone-7-pag/ – 2012-09-16 05:36:54

+0

看看這個問題http://stackoverflow.com/questions/12444816/how-to-pass-values-parameters-between-xaml-pages – 2013-05-13 23:43:33

回答

21

在他的書中"Programming Windows Phone 7"(第6章,第3節, 「共享數據中的網頁」) Charles Petzold建議親App類(衍生自Application)。每個頁面都可以通過Application.Current訪問。有趣的是字典PhoneApplicationService.Current.State。對墓碑操作很有用。整章可能對閱讀很有意思。

+0

而你不想要有全局狀態還有其他方法http://stackoverflow.com/questions/12444816/how-to-pass-values-parameters-between-xaml-pages – 2013-02-06 23:57:41

0

看看我在PhoneCore Framework中如何實現導航:A framework for building of WP7 application。不久之後,我在WP7導航之上構建了我的導航服務。它使用自定義頁面映射,並允許自動傳遞自定義參數以查看模型。

-1

您應該將對象保存到IsolatedStorage。

只需使用Json.net庫將其序列化並將該字符串保存到IsolatedStorage即可。在下一頁中,從IsolatedStorage中獲取字符串,並使用json.net庫將其轉換回您想要的對象!

+0

我認爲這是過度殺傷只是爲了傳遞意見。將數據放入App對象更好。 – Nathan 2012-05-02 13:35:22

0

使用全局變量,作出GlobalVariables一個新的類:

public static class GlobalVariables 
{ 
    public static string my_string = ""; 
    public static int my_int = -1; 
} 

然後你就可以訪問全局變量類不同的網頁:

GlobalVariables.variable_name;