/// <summary> /// Handler called when user taps one of the RSS feed icons /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; int pageIndex = RSSFeedsPanorama.SelectedIndex; PanoramaItem item = RSSFeedsPanorama.SelectedItem as PanoramaItem; RSSPage page = item.DataContext as RSSPage; RSSFeed feed = button.DataContext as RSSFeed; int feedIndex = page.Feeds.IndexOf(feed); if (feedIndex >= 0) // Act only on buttons on current page { NavigationService.Navigate(new Uri("/Views/FeedPivot.xaml?id=" + feedIndex.ToString() + "&page=" + pageIndex.ToString(), UriKind.Relative)); } }
/// <summary> /// Overridden OnNavigatedTo handler /// </summary> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (isNewInstance) { pageId = int.Parse(NavigationContext.QueryString["pageId"]); page = RSSService.GetRSSPage(pageId); if (page != null) { PageTitle.Text = page.Title; subscriptionsListBox.ItemsSource = page.Feeds; } isNewInstance = false; } }
/// <summary> /// Overridden OnNavigatedTo handler /// </summary> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (isNewInstance) { originalFeedId = feedId = int.Parse(NavigationContext.QueryString["id"]); pageId = int.Parse(NavigationContext.QueryString["page"]); page = RSSService.GetRSSPage(pageId); InitializePivotViews(page); // Switch to the previously selected PivotItem, if it has been stored if (State.ContainsKey("feedPivotIndex")) { RSSItemsPivot.SelectedIndex = (int)State["feedPivotIndex"]; } isNewInstance = false; } }
/// <summary> /// Method that initializes all pivot items /// </summary> /// <param name="page"></param> private void InitializePivotViews(RSSPage page) { // Perform initialization only on the 1st time if (RSSItemsPivot.Items.Count == 0) { // Initialize PivotItems // Initialize them starting from the one that was tapped // so that when the PivotItems show up, the active one // is already the tapped one. Otherwise we'd have to wait // for all of the PivotItems to load and then change the // SelectedIndex, which would result in animation in the // Pivot control. for (int i = 0; i < page.Feeds.Count; i++) { int j = originalFeedId + i; if (j >= page.Feeds.Count) { j = j % page.Feeds.Count; } CreatePivotItem(page.Feeds[j]); } } }