您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

windows phone页面间传递数据

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 页面间传递数据包括两个问题
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));//导航至指定页面