Guest User

MainPage

a guest
Apr 4th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 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 string CocktailId { get; set; }
  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.             w.DownloadStringAsync(
  37.               new Uri("http://192.168.1.103/getdata.php"));
  38.         }
  39.  
  40.         private void CocktailList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  41.         {
  42.             //MessageBox.Show("Cocktail mit ID " + CocktailList.SelectedIndex);
  43.  
  44.             // If selected index is -1 (no selection) do nothing
  45.             if (CocktailList.SelectedIndex == -1)
  46.                 return;
  47.  
  48.             // Navigate to the new page
  49.             NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + CocktailList.SelectedIndex, UriKind.Relative));
  50.  
  51.             // Reset selected index to -1 (no selection)
  52.             CocktailList.SelectedIndex = -1;
  53.  
  54.         }
  55.  
  56.  
  57.  
  58.     }
  59.  
  60.  
  61.     public class Cocktails
  62.     {
  63.         public string id { get; set; }
  64.         public string name { get; set; }
  65.         public string image { get; set; }
  66.         public string description { get; set; }
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment