Guest User

Untitled

a guest
Apr 17th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 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.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using Newtonsoft.Json;
  14. using Microsoft.Phone.Reactive;
  15.  
  16. namespace Cocktails
  17. {
  18.     public partial class MainPage : PhoneApplicationPage
  19.     {
  20.         public static int CocktailId;
  21.        
  22.  
  23.         // Constructor
  24.         public MainPage()
  25.         {
  26.             InitializeComponent();
  27.             var w = new WebClient();
  28.             Observable
  29.               .FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted")
  30.               .Subscribe(r =>
  31.               {
  32.                   var deserialized =
  33.                     JsonConvert.DeserializeObject<List<Cocktails>>(r.EventArgs.Result);
  34.                   CocktailList.ItemsSource = deserialized;
  35.                  
  36.               });
  37.             w.DownloadStringAsync(
  38.               new Uri("http://192.168.1.103/getdata.php"));
  39.         }
  40.  
  41.         private void CocktailList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  42.         {
  43.             //MessageBox.Show("Cocktail mit ID " + CocktailList.SelectedIndex);
  44.  
  45.             // If selected index is -1 (no selection) do nothing
  46.             if (CocktailList.SelectedIndex == -1)
  47.                 return;
  48.  
  49.             // Navigate to the new page
  50.             NavigationService.Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));
  51.             CocktailId = CocktailList.SelectedIndex;
  52.  
  53.             // Reset selected index to -1 (no selection)
  54.             CocktailList.SelectedIndex = -1;
  55.  
  56.         }
  57.  
  58.  
  59.  
  60.     }
  61.  
  62.  
  63.     public class Cocktails
  64.     {
  65.         public string id { get; set; }
  66.         public string name { get; set; }
  67.         public string image { get; set; }
  68.         public string description { get; set; }
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment