如何借助Azure移动服务开发通用应用程序?

译文
云计算
本文分享了Azure移动服务,开发通用应用程序的方法和主要步骤。完成整个动手实验室估计所用的时间为90分钟。感兴趣的朋友们一定要耐心看完。

概述

该实验室将为Azure移动服务(Azure Mobile Services)提供几个学习要点。

  • 如何创建一个通用项目,旨在共享Windows商店的应用程序与Windows Phone应用程序之间的代码。
  • 如何实现让Toast消息得以出现在设备上的推送通知功能。
  • 如何处理数据库,以便添加表、列和数据。
  • 如何为Windows Phone应用程序添加代码,让你能够检索记录,并通过列表视图控件显示记录。

前提条件

想完成这个动手实验室,需要下列内容:

  • 订阅Windows Azure,可在此注册下载免费试用版:http://azure.microsoft.com/en-us/pricing/free-trial/?WT.mc_id=AEDA13C29
  • Windows Phone开发者帐户
  • Windows 8.1和Visual Studio 2013更新版

具体步骤

这个动手实验室包括下面几大步骤:完成该实验室估计所用的时间为90分钟。

***个步骤:创建一个通用项目

在这个步骤中,你将配置在实验室中需要用到的三个Windows Azure虚拟机。具体来说,你要完成下列任务:

第1个任务:开发一个通用应用程序

通用应用程序让你可以共享平板电脑应用程序和手机应用程序之间的代码。Visual Studio解决方案含有三个项目。一个项目面向基于Windows 8台式机、笔记本电脑或平板电脑的应用程序。第二个项目面向手机应用程序。第三个项目是另外两个项目之间共享的代码库。

1. 你需要创建一个新的手机项目。从File(文件)菜单,选择New/Project(新建/项目)。

创建新的手机项目

2.从左边的模块面板上,选择Universal apps(通用应用程序),如下所示。下一步,选择Hub App模板,然后为你的项目提供一个name(名称)。

创建并命名你的项目

第2个任务:添加推送通知功能

这个任务侧重于将推送通知功能添加到手机应用程序中。你***要为手机应用程序预留一个名称。你还要修改及/或创建在微软数据中心托管、支持推送通知的移动服务。

1. 你的项目现已创建完毕。下一步就是添加推送通知服务。现在你添加支持push notifications(推送通知)的功能。鼠标右击解决方案资源管理器中的手机项目,依次选择Add/Push Notification(添加/推送通知)。

添加推送通知

2. 向导会告知你接下来会发生什么:

(1)会创建推送通道URI。这是客户端应用程序用来侦听和处理推送通知的一种机制;

(2)手机项目还会由代码加以改动,以便处理收到的推送通知;

(3)你的移动服务帐户将被修改,以便支持推送通知。我们将创建一项新的移动服务,以支持该应用程序。

了解将要进行的变更

3.你需要登入到Windows Phone Developer Portal(Windows Phone开发者门户)。这一步假设你有一个有效的Windows Phone开发者手机帐户可以使用。如果你没有Windows Phone开发者帐户,那可以在此注册:http://www.windowsphone.com/account。现在,你可以为你的手机应用程序表明名称。这是会出现在Windows Phone商店里的那个名称。名称必须具有唯一性。

预留一个手机应用程序名称

4.你现在要创建一项服务,这意味着将使用你的Windows Azure帐户,创建一项的Azure移动服务。这意味着你之前已经过注册,可以使用Windows Azure。

创建一项新的Azure移动服务

5. 现在你要为Azure移动服务提供一个名称。你还要选择运行时环境、区域、数据库、用户名和密码。我们选择创建计费的SQL数据库。你的名称会有别于universal-push-notif。你不用改动默认的运行时环境:JavaScript,但可以选择你的区域。

创建一项移动服务

6. 输入服务器用户名。

提供用户名

7. 你现在会注意到,你的Azure移动服务已创建完毕。你的名称会不一样。

验证刚创建的Azure移动服务

8. 现在你要验证摘要页面。你会看到,你的手机应用程序名称和Azure移动服务都已经创建完毕。系统在此还会告知你:Visual Studio中的项目源代码将被修改。

查看Visual Studio向导的摘要信息

9. 现在你可以看到Visual Studio中的已完成项目。

查看Visual Studio中的已完成项目

第3个任务:测试推送通知

在第3个任务中,你要验证推送通知功能操作正常。你要在仿真器中运行手机应用程序,并加以验证,确保看到文本Sample Toast。

1. 鼠标右击手机项目,选择"set as a startup project"(设为开始项目)。

设置开始项目

2. 从任务栏中运行应用程序和仿真器

开始应用程序和仿真器

3.现在你能够看到Toast通知已出现。

查看推送通知和应用程序

4. Sample Toast信息现在会出现。

查看Toast消息

#p#

第二个步骤:充分利用应用程序中的关系型数据

在这个步骤中,我们将充分利用手机应用程序中的SQL Server数据。

第1个任务:添加表、插入数据

在该任务中,我们将添加表、插入列,然后插入数据。

1.从左面板中选择mobile services(移动服务)。我们之前创建的服务名为universal-push-notif。点击图中所标的箭头,即可深入分析该服务。

深入分析universal-push-notif

2.你现在从菜单中选择data(数据)。

从菜单中选择数据

3. 你要add a table(添加表)

添加表

4. 将该表命名为ViewStatus。

为新表命名

5.现在你要验证该表已创建完毕。下几个步骤将包括adding a column(添加列),然后inserting some data(插入一些数据)。点击图中所标的箭头,即可深入分析ViewStatus。

深入分析ViewStatus表

6.请注意:该表随带一些默认的列。点击columns(列),然后点击屏幕底部的add column(添加列)。

添加一个新的列

7.新的列名称将是statustext。不用改动数据类型的默认值:string(字符串)。

为你添加的新列命名

8.现在你验证新列已添加完毕。在下面几个步骤中,我们将为该刚修改的列添加数据。

验证表结构

9.现在你浏览到门户的不同部分。在左边菜单上,选择SQL database(SQL数据库)。你应该会看到数据库的名称。我的数据库名叫universal-push-notif。你的名称会不一样。点击图中所标的箭头,即可深入了解该数据库的详细信息。

深入数据库,以便能够插入数据

10.为了能够插入数据,你需要管理数据库。从底部菜单选择Manage(管理)。

管理数据库,以便插入数据

11.你需要确认你目前的IP地址将被添加到现有防火墙规则列表,让你目前的计算机能够连接到该数据库。开发者定义了允许哪些IP地址连接到数据库。

为防火墙规则添加一个新的IP地址

12.要注意:现在你能创建一个新的查询。从上方的菜单栏选择New Query(新建查询)。

构建新的查询,以便插入数据

13.现在你要键入4个sql插入语句,如下所示。要注意:数据库名称已换成了有破折号的下划线。在键入4个插入语句后,从顶部菜单栏选择Run(运行)。

键入4个插入语句,然后运行这些语句。

第2个任务:添加代码以查看数据

Windows Phone应用程序已经拥有从数据库检索数据所需要的大部分基础架构。在该任务中,我们将添加必要的C#和XAML代码,以便检索和显示数据。

1.打开文件HubPage.xaml.cs。你要添加连接到数据库的代码。添加下列代码,以便你可以从ViewStatus表检索记录列表。

从ViewStatus表检索数据

2.在文件顶部,添加下列using语句。

添加using语句

3.你需要添加TableViewStatus.cs类文件。鼠标右击手机项目,选择Add class(添加类)。粘贴下列代码:

TableViewStatus.cs

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. using System.Threading.Tasks; 
  6. using Microsoft.WindowsAzure.MobileServices; 
  7. using Newtonsoft.Json; 
  8. namespace UniversalPushNotif 
  9. public class ViewStatus 
  10. public string Id { get; set; } 
  11. [JsonProperty(PropertyName = "StatusText")] 
  12. public string StatusText { get; set; } 

1.你现在执行实际查询数据库记录的任务。你要修改NavigationHelper_LoadState()方法。添加代码,所下所示。

添加执行查询的代码

2.你现在添加采集来源,采集来源将充当数据库记录的容器。你在下一步添加的列表视图控件将引用该采集来源作为来源。

添加采集来源

3.现在你要修改HubPage.xaml标记代码。你要添加显示记录的列表视图控件。本文末尾提供了完整代码。

为HubPage.xaml添加代码

4.我们现在运行项目,以便你可以测试数据库记录已被检索。运行项目。

运行项目

5.你现在可以看到,记录已检索成功。你还能看到sample toast消息也正常显示。

查看正确的结果

#p#

结束语

这篇指导文章演示了一些重要的概念:

  • 如何创建一个通用项目,旨在共享Windows商店的应用程序与Windows Phone应用程序之间的代码。
  • 如何实现让Toast消息得以出现在设备上的推送通知功能。
  • 如何处理数据库,以便添加表、列和数据。
  • 如何为Windows Phone应用程序添加代码,让你能够检索记录,并通过列表视图控件显示记录。

附文:代码清单

你可以在此下载整个项目:http://1drv.ms/1hRB1tP

HubPage.xaml

  1. <Page 
  2. x:Class="UniversalPushNotif.HubPage" 
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5. xmlns:local="using:UniversalPushNotif" 
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  8. DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 
  9. d:DataContext="{Binding Source={d:DesignData Source=../UniversalPushNotif.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" 
  10. xmlns:data="using:UniversalPushNotif.Data" 
  11. mc:Ignorable="d"> 
  12. <Page.Resources> 
  13. <ResourceDictionary> 
  14. <ResourceDictionary.ThemeDictionaries> 
  15. <ResourceDictionary x:Key="Default"> 
  16. <ImageBrush 
  17. x:Key="HubBackgroundImageBrush" 
  18. ImageSource="Assets/HubBackground.png"/> 
  19. </ResourceDictionary> 
  20. <ResourceDictionary x:Key="HighContrast"> 
  21. <ImageBrush 
  22. x:Key="HubBackgroundImageBrush" 
  23. ImageSource="{x:Null}"/> 
  24. </ResourceDictionary> 
  25. </ResourceDictionary.ThemeDictionaries> 
  26. <!--Grid-appropriate item template as seen in section 2 --> 
  27. <DataTemplate x:Key="Standard200x180TileItemTemplate"> 
  28. <Grid Width="180"> 
  29. <Grid.RowDefinitions> 
  30. <RowDefinition Height="Auto"/> 
  31. <RowDefinition Height="Auto"/> 
  32. </Grid.RowDefinitions> 
  33. <Border 
  34. Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
  35. Height="173" 
  36. Width="173" 
  37. Grid.Row="0" 
  38. HorizontalAlignment="Left"> 
  39. <Image 
  40. Source="{Binding ImagePath}" 
  41. Stretch="UniformToFill" 
  42. AutomationProperties.Name="{Binding Title}" 
  43. Height="173" 
  44. Width="173"/> 
  45. </Border> 
  46. <TextBlock 
  47. Text="{Binding Title}" 
  48. Style="{ThemeResource BaseTextBlockStyle}" 
  49. Typography.Capitals="SmallCaps" 
  50. Grid.Row="1" 
  51. Margin="0,12,0,0" 
  52. IsTextScaleFactorEnabled="False"/> 
  53. </Grid> 
  54. </DataTemplate> 
  55. <DataTemplate x:Key="StandardTripleLineItemTemplate"> 
  56. <Grid> 
  57. <Grid.ColumnDefinitions> 
  58. <ColumnDefinition Width="Auto"/> 
  59. <ColumnDefinition Width="*"/> 
  60. </Grid.ColumnDefinitions> 
  61. <Border 
  62. Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
  63. Height="99" 
  64. Width="99" 
  65. Grid.Column="0" 
  66. HorizontalAlignment="Left"> 
  67. <Image 
  68. Source="{Binding ImagePath}" 
  69. Stretch="UniformToFill" 
  70. AutomationProperties.Name="{Binding Title}" 
  71. Height="99" 
  72. Width="99"/> 
  73. </Border> 
  74. <StackPanel 
  75. Grid.Column="1" 
  76. Margin="12,0,0,0"> 
  77. <TextBlock 
  78. Text="{Binding Title}" 
  79. Style="{ThemeResource ListViewItemTextBlockStyle}"/> 
  80. <TextBlock 
  81. Text="{Binding Subtitle}" 
  82. Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/> 
  83. <TextBlock 
  84. Text="{Binding Description}" 
  85. Style="{ThemeResource ListViewItemContentTextBlockStyle}"/> 
  86. </StackPanel> 
  87. </Grid> 
  88. </DataTemplate> 
  89. <DataTemplate x:Key="StandardDoubleLineItemTemplate"> 
  90. <Grid> 
  91. <Grid.ColumnDefinitions> 
  92. <ColumnDefinition Width="Auto"/> 
  93. <ColumnDefinition Width="*"/> 
  94. </Grid.ColumnDefinitions> 
  95. <Border 
  96. Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
  97. Height="99" 
  98. Width="99" 
  99. Grid.Column="0" 
  100. HorizontalAlignment="Left"> 
  101. <Image 
  102. Source="{Binding ImagePath}" 
  103. Stretch="UniformToFill" 
  104. AutomationProperties.Name="{Binding Title}" 
  105. Height="99" 
  106. Width="99"/> 
  107. </Border> 
  108. <StackPanel 
  109. Grid.Column="1" 
  110. Margin="12,0,0,0"> 
  111. <TextBlock 
  112. Text="{Binding Title}" 
  113. Style="{ThemeResource ListViewItemTextBlockStyle}"/> 
  114. <TextBlock 
  115. Text="{Binding Subtitle}" 
  116. Style="{ThemeResource ListViewItemContentTextBlockStyle}"/> 
  117. </StackPanel> 
  118. </Grid> 
  119. </DataTemplate> 
  120. <CollectionViewSource 
  121. x:Name="viewStatusCollection" 
  122. Source="{Binding Items}"/> 
  123. </ResourceDictionary> 
  124. </Page.Resources> 
  125. <Grid x:Name="LayoutRoot"> 
  126. <Hub 
  127. x:Name="Hub" 
  128. x:Uid="Hub" 
  129. Header="application name" 
  130. Background="{ThemeResource HubBackgroundImageBrush}"> 
  131. <HubSection 
  132. x:Uid="HubSection1" 
  133. Header="SECTION 1"> 
  134. <DataTemplate> 
  135. <ListView 
  136. x:Name="ListView2" 
  137. Margin="0,0,0,4" 
  138. Width="520" 
  139. Height="405" 
  140. Background="#FF1D1D1D" 
  141. ShowsScrollingPlaceholders="False" 
  142. BorderThickness="0" 
  143. VerticalAlignment="Stretch" 
  144. HorizontalAlignment="Left" 
  145. ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
  146. ItemsSource="{Binding Source={StaticResource viewStatusCollection}}" 
  147. FontFamily="Global User Interface"> 
  148. <ListView.ItemsPanel> 
  149. <ItemsPanelTemplate> 
  150. <VirtualizingStackPanel VerticalAlignment="Top"/> 
  151. </ItemsPanelTemplate> 
  152. </ListView.ItemsPanel> 
  153. <ListView.ItemContainerTransitions> 
  154. <TransitionCollection> 
  155. <EntranceThemeTransition/> 
  156. </TransitionCollection> 
  157. </ListView.ItemContainerTransitions> 
  158. <ListView.ItemTemplate> 
  159. <DataTemplate> 
  160. <StackPanel 
  161. HorizontalAlignment="Left" 
  162. Orientation="Horizontal" 
  163. Background="#FF1D1D1D" 
  164. Margin="5,5,5,5"> 
  165. <Grid 
  166. VerticalAlignment="Center" 
  167. Background="#FF1D1D1D"> 
  168. <StackPanel 
  169. Orientation="Vertical" 
  170. VerticalAlignment="Center"> 
  171. <TextBlock 
  172. Text="{Binding StatusText}" 
  173. FontSize="14.667" 
  174. FontFamily="Segoe UI" 
  175. Margin="5,0,0,0"/> 
  176. </StackPanel> 
  177. </Grid> 
  178. </StackPanel> 
  179. </DataTemplate> 
  180. </ListView.ItemTemplate> 
  181. </ListView> 
  182. </DataTemplate> 
  183. </HubSection> 
  184. <HubSection 
  185. x:Uid="HubSection2" 
  186. Header="SECTION 2" 
  187. Width="Auto" 
  188. DataContext="{Binding Groups[0]}"> 
  189. <DataTemplate> 
  190. <GridView 
  191. ItemsSource="{Binding Items}" 
  192. AutomationProperties.AutomationId="ItemGridView" 
  193. AutomationProperties.Name="Items In Group" 
  194. ItemTemplate="{StaticResource Standard200x180TileItemTemplate}" 
  195. SelectionMode="None" 
  196. IsItemClickEnabled="True" 
  197. ItemClick="ItemView_ItemClick" 
  198. ContinuumNavigationTransitionInfo.ExitElementContainer="True"> 
  199. <GridView.ItemsPanel> 
  200. <ItemsPanelTemplate> 
  201. <ItemsWrapGrid/> 
  202. </ItemsPanelTemplate> 
  203. </GridView.ItemsPanel> 
  204. </GridView> 
  205. </DataTemplate> 
  206. </HubSection> 
  207. <HubSection 
  208. x:Uid="HubSection3" 
  209. Header="SECTION 3" 
  210. DataContext="{Binding Groups[1]}"> 
  211. <DataTemplate> 
  212. <ListView 
  213. AutomationProperties.AutomationId="ItemListViewSection3" 
  214. AutomationProperties.Name="Items In Group" 
  215. SelectionMode="None" 
  216. IsItemClickEnabled="True" 
  217. ItemsSource="{Binding Items}" 
  218. ItemTemplate="{StaticResource StandardTripleLineItemTemplate}" 
  219. ItemClick="ItemView_ItemClick" 
  220. ContinuumNavigationTransitionInfo.ExitElementContainer="True"> 
  221. </ListView> 
  222. </DataTemplate> 
  223. </HubSection> 
  224. <HubSection 
  225. x:Uid="HubSection4" 
  226. Header="SECTION 4" 
  227. DataContext="{Binding Groups[2]}"> 
  228. <DataTemplate> 
  229. <ListView 
  230. AutomationProperties.AutomationId="ItemListViewSection4" 
  231. AutomationProperties.Name="Items In Group" 
  232. SelectionMode="None" 
  233. IsItemClickEnabled="True" 
  234. ItemsSource="{Binding Items}" 
  235. ItemClick="ItemView_ItemClick" 
  236. ContinuumNavigationTransitionInfo.ExitElementContainer="True"> 
  237. <ListView.ItemTemplate> 
  238. <DataTemplate> 
  239. <StackPanel> 
  240. <TextBlock 
  241. Text="{Binding Title}" 
  242. Style="{ThemeResource ListViewItemTextBlockStyle}"/> 
  243. <TextBlock 
  244. Text="{Binding Subtitle}" 
  245. Style="{ThemeResource ListViewItemContentTextBlockStyle}"/> 
  246. </StackPanel> 
  247. </DataTemplate> 
  248. </ListView.ItemTemplate> 
  249. </ListView> 
  250. </DataTemplate> 
  251. </HubSection> 
  252. <HubSection 
  253. x:Uid="HubSection5" 
  254. Header="SECTION 5" 
  255. DataContext="{Binding Groups[3]}"> 
  256. <DataTemplate> 
  257. <ListView 
  258. AutomationProperties.AutomationId="ItemListViewSection5" 
  259. AutomationProperties.Name="Items In Group" 
  260. SelectionMode="None" 
  261. IsItemClickEnabled="True" 
  262. ItemsSource="{Binding Items}" 
  263. ItemTemplate="{StaticResource StandardDoubleLineItemTemplate}" 
  264. ItemClick="ItemView_ItemClick" 
  265. ContinuumNavigationTransitionInfo.ExitElementContainer="True"> 
  266. </ListView> 
  267. </DataTemplate> 
  268. </HubSection> 
  269. </Hub> 
  270. </Grid> 
  271. </Page> 

HubPage.xaml.cs

  1. using UniversalPushNotif.Common; 
  2. using UniversalPushNotif.Data; 
  3. using System; 
  4. using System.Collections.Generic; 
  5. using System.IO; 
  6. using System.Linq; 
  7. using System.Runtime.InteropServices.WindowsRuntime; 
  8. using Windows.ApplicationModel.Resources; 
  9. using Windows.Foundation; 
  10. using Windows.Foundation.Collections; 
  11. using Windows.Graphics.Display; 
  12. using Windows.UI.Core; 
  13. using Windows.UI.ViewManagement; 
  14. using Windows.UI.Xaml; 
  15. using Windows.UI.Xaml.Controls; 
  16. using Windows.UI.Xaml.Controls.Primitives; 
  17. using Windows.UI.Xaml.Data; 
  18. using Windows.UI.Xaml.Input; 
  19. using Windows.UI.Xaml.Media; 
  20. using Windows.UI.Xaml.Media.Imaging; 
  21. using Windows.UI.Xaml.Navigation; 
  22. using Microsoft.WindowsAzure.MobileServices; 
  23. using Newtonsoft.Json; 
  24. // The Universal Hub Application project template is documented at http://go.microsoft.com/fwlink/?LinkID=391955 
  25. namespace UniversalPushNotif 
  26. /// 
  27. /// A page that displays a grouped collection of items. 
  28. /// 
  29. public sealed partial class HubPage : Page 
  30. private readonly NavigationHelper navigationHelper; 
  31. private readonly ObservableDictionary defaultViewModel = new ObservableDictionary(); 
  32. private readonly ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("Resources"); 
  33. // Add this code 
  34. // An asynchronous data source that can wrap the results of a Mobile Services query 
  35. // in a way that's easily consumed by Xaml collection controls like ListView, 
  36. // GridView or ListBox. 
  37. private MobileServiceCollection<ViewStatus, ViewStatus> viewStatusList; 
  38. // Get a list of records from the ViewStatus table 
  39. private IMobileServiceTable<ViewStatus> tableViewStatus = 
  40. App.universal_push_notifClient.GetTable<ViewStatus>(); 
  41. public HubPage() 
  42. this.InitializeComponent(); 
  43. // Hub is only supported in Portrait orientation 
  44. DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait; 
  45. this.NavigationCacheMode = NavigationCacheMode.Required; 
  46. this.navigationHelper = new NavigationHelper(this); 
  47. this.navigationHelper.LoadState += this.NavigationHelper_LoadState; 
  48. this.navigationHelper.SaveState += this.NavigationHelper_SaveState; 
  49. /// 
  50. /// Gets the <>"NavigationHelper"/> associated with this <>"Page"/>
  51. /// 
  52. public NavigationHelper NavigationHelper 
  53. get { return this.navigationHelper; } 
  54. /// 
  55. /// Gets the view model for this <>"Page"/>
  56. /// This can be changed to a strongly typed view model. 
  57. /// 
  58. public ObservableDictionary DefaultViewModel 
  59. get { return this.defaultViewModel; } 
  60. /// 
  61. /// Populates the page with content passed during navigation.  Any saved state is also 
  62. /// provided when recreating a page from a prior session. 
  63. /// 
  64. /// <>"sender"> 
  65. /// The source of the event; typically <>"NavigationHelper"/> 
  66. /// 
  67. /// <>"e">Event data that provides both the navigation parameter passed to 
  68. /// <>"Frame.Navigate(Type, object)"/> when this page was initially requested and 
  69. /// a dictionary of state preserved by this page during an earlier 
  70. /// session.  The state will be null the first time a page is visited. 
  71. private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) 
  72. // TODO: Create an appropriate data model for your problem domain to replace the sample data 
  73. var sampleDataGroups = await SampleDataSource.GetGroupsAsync(); 
  74. this.DefaultViewModel["Groups"] = sampleDataGroups; 
  75. viewStatusList = await tableViewStatus.ToCollectionAsync(); 
  76. viewStatusCollection.Source = viewStatusList
  77. /// 
  78. /// Preserves state associated with this page in case the application is suspended or the 
  79. /// page is discarded from the navigation cache.  Values must conform to the serialization 
  80. /// requirements of <>"SuspensionManager.SessionState"/>
  81. /// 
  82. /// <>"sender">The source of the event; typically <>"NavigationHelper"/> 
  83. /// <>"e">Event data that provides an empty dictionary to be populated with 
  84. /// serializable state. 
  85. private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e) 
  86. // TODO: Save the unique state of the page here. 
  87. /// 
  88. /// Shows the details of a clicked group in the <>"SectionPage"/>
  89. /// 
  90. /// <>"sender">The source of the click event. 
  91. /// <>"e">Details about the click event. 
  92. private void GroupSection_ItemClick(object sender, ItemClickEventArgs e) 
  93. var groupId = ((SampleDataGroup)e.ClickedItem).UniqueId; 
  94. if (!Frame.Navigate(typeof(SectionPage), groupId)) 
  95. throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage")); 
  96. /// 
  97. /// Shows the details of an item clicked on in the <>"ItemPage"/> 
  98. /// 
  99. /// <>"sender">The source of the click event. 
  100. /// <>"e">Defaults about the click event. 
  101. private void ItemView_ItemClick(object sender, ItemClickEventArgs e) 
  102. var itemId = ((SampleDataItem)e.ClickedItem).UniqueId; 
  103. if (!Frame.Navigate(typeof(ItemPage), itemId)) 
  104. throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage")); 
  105. #region NavigationHelper registration 
  106. /// 
  107. /// The methods provided in this section are simply used to allow 
  108. /// NavigationHelper to respond to the page's navigation methods. 
  109. /// 
  110. /// Page specific logic should be placed in event handlers for the 
  111. /// <>"NavigationHelper.LoadState"/> 
  112. /// and <>"NavigationHelper.SaveState"/>
  113. /// The navigation parameter is available in the LoadState method 
  114. /// in addition to page state preserved during an earlier session. 
  115. /// 
  116. /// 
  117. /// <>"e">Event data that describes how this page was reached. 
  118. protected override void OnNavigatedTo(NavigationEventArgs e) 
  119. this.navigationHelper.OnNavigatedTo(e); 
  120. protected override void OnNavigatedFrom(NavigationEventArgs e) 
  121. this.navigationHelper.OnNavigatedFrom(e); 
  122. #endregion 

原文链接:http://blogs.msdn.com/b/brunoterkaly/archive/2014/04/13/how-to-create-universal-applications-with-azure-mobile-services-that-leverage-push-notifications-and-database-insertion-and-data-retrieval.aspx

责任编辑:黄丹 来源: 51CTO.com
相关推荐

2013-09-30 10:19:46

SAP

2015-02-05 09:56:53

2013-02-22 09:28:45

MEAP软件移动应用开发HTML5

2010-10-15 09:39:22

MeeGoQt

2011-12-06 10:10:59

云计算移动应用

2011-02-22 10:23:43

2022-01-20 15:33:30

区块链创新初创公司

2011-11-23 10:06:32

Azure微软移动应用

2011-05-05 18:08:43

云计算Windows AzuPaaS

2010-08-18 09:23:19

Flash Lite移动应用程序开发

2011-03-21 14:31:36

Azure应用程序

2011-03-21 15:22:04

Azure应用程序

2022-09-19 00:37:13

SaaS云计算开发

2019-04-17 08:00:00

Linuxrestic目录

2011-03-10 10:20:37

应用程序Windows Azu

2015-01-14 09:41:28

跨平台移动应用Linux开发

2010-08-11 09:45:03

2018-12-11 11:41:14

物联网应用程序IOT

2018-12-28 14:10:57

开发工具 移动应用

2011-02-24 12:20:32

点赞
收藏

51CTO技术栈公众号