Exemplo n.º 1
0
 private void LoadNasaRSSData(object sender, OpenReadCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FeedsContractType));
         FeedsContractType          feed       = (FeedsContractType)serializer.ReadObject(e.Result) ?? new FeedsContractType();
         LayoutUtil.GenerateDynamicGridSkeleton(3, ContentPanel);
         ///Generating 3 column grid
         int row = 0, col = 0;
         for (int i = 0; i < feed.value.items.Length; i++)
         {
             if (i > 0 && i % 3 == 0)
             {
                 RowDefinition newrow = new RowDefinition();
                 ContentPanel.RowDefinitions.Add(newrow);
                 col = 0;
                 row++;
             }
             Grid grid = new Grid();
             grid.Width      = 145;
             grid.Height     = 145;
             grid.Background = new SolidColorBrush(Color.FromArgb(255, 42, 58, 112));
             TextBlock date = new TextBlock();
             date.Text = DataUtil.UnixTimeStampToDateCustom(feed.value.items[i].published.utime, "MM/dd/yyyy");
             date.VerticalAlignment   = VerticalAlignment.Top;
             date.HorizontalAlignment = HorizontalAlignment.Center;
             Image img = new Image();
             img.Source  = new BitmapImage(new Uri("/Assets/Images/rss.png", UriKind.Relative));
             img.Width   = 100;
             img.Height  = 85;
             img.Opacity = 0.10;
             Grid.SetColumn(grid, col++);
             Grid.SetRow(grid, row);
             grid.Resources.Add("feedindex", i);
             grid.Tap += (o, ev) =>
             {
                 Grid broadcaster = (Grid)o;
                 PhoneApplicationService.Current.State["allfeeds"]  = feed.value.items;
                 PhoneApplicationService.Current.State["feedindex"] = broadcaster.Resources["feedindex"];
                 this.NavigationService.Navigate(new Uri("/RSSDataPage.xaml", UriKind.Relative));
             };
             grid.Children.Add(date);
             grid.Children.Add(img);
             ContentPanel.Children.Add(grid);
         }
     }
     else
     {
         MessageBox.Show(EnumUtil.getEnumDescription(MessagesEnum.ConnectionErrors.NoConnectionError));
     }
     Image.Opacity = 0.0;
 }