萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> windows phone頁面間傳遞數據

windows phone頁面間傳遞數據

 頁面間傳遞數據包括兩個問題
1、如何從源頁面傳遞數據到目標頁面?
下面例子提供解決上面問題的方案。
源頁面MainPage.xaml內容區域包含一個TextBlock,如
<TextBlock HorizontalAlignment="Center" Name="txt1" Text="navigate to 2nd page" VerticalAlignment="Center" ManipulationStarted="txt1_ManipulationStarted" />
MainPage.xaml.cs代碼如下所示:
namespace PhoneApp2
{
public partial class MainPage : PhoneApplicationPage
{
Random rand = new Random();
// 構造函數
public MainPage()
{
InitializeComponent();
}
private void txt1_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
String destination = "/Page1.xaml";
if (this.ContentPanel.Background is SolidColorBrush)
{
Color clr = (this.ContentPanel.Background as SolidColorBrush).Color;
destination += String.Format("?Red={0}&Green={1}&Blue={2}",clr.R,clr.G,clr.B);
}
this.NavigationService.Navigate(new Uri(destination, UriKind.Relative));//導航至指定頁面

copyright © 萬盛學電腦網 all rights reserved