Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Navigation;
  8. using Microsoft.Phone.Controls;
  9. using Microsoft.Phone.Shell;
  10. using PhoneApp5.Resources;
  11. using Newtonsoft.Json;
  12.  
  13. namespace PhoneApp5
  14. {
  15. public partial class MainPage : PhoneApplicationPage
  16. {
  17. // Constructor
  18. public MainPage()
  19. {
  20. InitializeComponent();
  21.  
  22.  
  23.  
  24. string json = @"{
  25. 'Email': 'james@example.com',
  26. 'Active': true,
  27. 'CreatedDate': '2013-01-20T00:00:00Z'
  28. }";
  29.  
  30. string jsonx = @"{
  31. 'Table1': [
  32. {
  33. 'id': 0,
  34. 'item': 'item 0'
  35. },
  36. {
  37. 'id': 1,
  38. 'item': 'item 1'
  39. }
  40. ]
  41. }";
  42.  
  43.  
  44.  
  45. Account account = JsonConvert.DeserializeObject<Account>(json);
  46.  
  47. // Console.WriteLine(account.Email);
  48. // james@example.com
  49. MessageBox.Show(account.Email);
  50.  
  51. list.ItemsSource = new BookList();
  52.  
  53. }
  54.  
  55.  
  56.  
  57. }
  58. public class BookList : List<Account>
  59. {
  60. public BookList()
  61. {
  62.  
  63.  
  64. }
  65.  
  66.  
  67. }
  68. public class Account
  69. {
  70. public string Email { get; set; }
  71. public bool Active { get; set; }
  72. public DateTime CreatedDate { get; set; }
  73. // public IList<string> Roles { get; set; }
  74.  
  75. }
  76.  
  77. ///////////////////////////
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. }
  86.  
  87. <phone:PhoneApplicationPage
  88. x:Class="PhoneApp5.MainPage"
  89. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  90. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  91. xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
  92. xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
  93. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  94. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  95. mc:Ignorable="d"
  96. FontFamily="{StaticResource PhoneFontFamilyNormal}"
  97. FontSize="{StaticResource PhoneFontSizeNormal}"
  98. Foreground="{StaticResource PhoneForegroundBrush}"
  99. SupportedOrientations="Portrait" Orientation="Portrait"
  100. shell:SystemTray.IsVisible="True">
  101.  
  102. <Grid x:Name="LayoutRoot" Background="Transparent">
  103. <Grid.RowDefinitions>
  104. <RowDefinition Height="Auto"/>
  105. <RowDefinition Height="*"/>
  106. </Grid.RowDefinitions>
  107.  
  108.  
  109.  
  110. <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
  111. <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
  112. <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
  113. </StackPanel>
  114.  
  115. <!--ContentPanel - place additional content here-->
  116. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
  117. <phone:LongListSelector Name="list">
  118. <phone:LongListSelector.ItemTemplate>
  119. <DataTemplate>
  120. <StackPanel Orientation="Horizontal">
  121. <TextBlock Text="{Binding id}" />
  122. <TextBlock Text=" ( " />
  123. <TextBlock Text="{Binding item}" FontStyle="Italic" />
  124. <TextBlock Text=" )" />
  125. </StackPanel>
  126. </DataTemplate>
  127. </phone:LongListSelector.ItemTemplate>
  128. </phone:LongListSelector>
  129. </Grid>
  130.  
  131.  
  132. </Grid>
  133.  
  134. </phone:PhoneApplicationPage>
  135.  
  136. public class MyClass
  137. {
  138. public string Id { get; set; }
  139. public string Item { get; set; }
  140. }
  141.  
  142. public ObservableCollection<MyClass> MyClassCollection { get; set; }
  143.  
  144. MyClassCollection = JsonConvert.DeserializeObject<ObservableCollection<MyClass>>(e.Result);
  145.  
  146. <phone:LongListSelector Name="list" ItemsSource="{Binding MyClassCollection}">
  147. <phone:LongListSelector.ItemTemplate>
  148. <DataTemplate>
  149. <StackPanel Orientation="Horizontal">
  150. <TextBlock Text="{Binding id}" />
  151. <TextBlock Text=" ( " />
  152. <TextBlock Text="{Binding item}" FontStyle="Italic" />
  153. <TextBlock Text=" )" />
  154. </StackPanel>
  155. </DataTemplate>
  156. </phone:LongListSelector.ItemTemplate>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement