WindowsPhone開发教程8.docVIP

  • 1
  • 0
  • 约1.14万字
  • 约 15页
  • 2016-10-16 发布于重庆
  • 举报
WindowsPhone開发教程8

HYPERLINK /IPrograming/archive/2012/03/08/WindowsPhone_Share_Data.htmlWindows Phone笔记(8)页面间数据共享   通过HYPERLINK /IPrograming/archive/2012/03/07/WindowsPhone_Navigation_DataPass.html上一篇笔记我们知道了如何将源页面(调用Navigation函数的页面)的数据传递到目标页面中,但是当我们把这个顺序反过来,即把目标页面的数据返回给源页面时该怎么去做呢?在这篇笔记中我们给出三个解决方案。 1.通过App类保存页面共享数据   在Windows Phone笔记中的HYPERLINK /IPrograming/archive/2012/02/05/WindwosPhone_Hello_Windows_Phone.html第一篇笔记中我提到过:App类通常用来存储整个应用程序所使用的资源。该类从Application类中派生,我们通过Application.Current属性可以返回当前应用程序的Application对象,我们可以把理解为当前应用程序的实例,或者说一个全局变量,在各个页面都可以很轻易的访问到它。   和以前一样,我们通过一个简单的示例来学习如何使用APP类在页面间共享数据,和上一篇笔记中给出的示例类似,我们首先在APP.xaml.cs也就是为App类中定义一个类型为Color?的属性,用于存储在页面间需要共享的数据: 1 public partial class App : Application 2 { 3 //用于在页面间共享数据的公共属性,可空类型 4 public Color? ShareColor { get; set; } 5 } HYPERLINK javascript:void(0);复制代码 接着是这个示例的第一个页面MainPage.xaml的前端代码: 1 !--ContentPanel - 在此处放置其他内容-- 2 Grid x:Name=ContentPanel Grid.Row=1 Margin=12,0,12,0 3 TextBlock Padding=0 34 FontSize=32 HorizontalAlignment=Center Name=tblNavigationSecondPage Text=Navigation to SecondPage VerticalAlignment=Center ManipulationStarted=tblNavigationSecondPage_ManipulationStarted/ 4 /Grid HYPERLINK javascript:void(0);复制代码 MainPage.xmal.cs后台程序处理代码: 1 public partial class MainPage : PhoneApplicationPage 2 { 3 Random ran = new Random(); 4 // 构造函数 5 public MainPage() 6 { 7 InitializeComponent(); 8 } 9 10 private void tblNavigationSecondPage_ManipulationStarted(object sender, ManipulationStartedEventArgs e) 11 { 12 //ContentPanel背景颜色不为默认值时(Brush类null) 13 if (this.ContentPanel.Background is SolidColorBrush) 14 { 15 (Application.Current as App).ShareColor = (ContentPanel.Background as SolidColorBrush).Color; 16 17 this.NavigationService.Navigate(new Uri(/SecondPage.xaml, UriKind.Relative)); 18 e.Comple

文档评论(0)

1亿VIP精品文档

相关文档