ItemPage.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright © 2011-2012 Nokia Corporation. All rights reserved.
  3. * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
  4. * Other product and company names mentioned herein may be trademarks
  5. * or trade names of their respective owners.
  6. * See LICENSE.TXT for license information.
  7. */
  8. using System;
  9. using System.Windows;
  10. using System.Windows.Navigation;
  11. using Microsoft.Phone.Controls;
  12. using Microsoft.Phone.Tasks;
  13. using RSSReader.Model;
  14. namespace RSSReader.Views
  15. {
  16. /// <summary>
  17. /// Page that shows details a single RSS item
  18. /// </summary>
  19. public partial class ItemPage : PhoneApplicationPage
  20. {
  21. /// <summary>
  22. /// True when this object instance has been just created, otherwise false
  23. /// </summary>
  24. private bool isNewInstance = true;
  25. /// <summary>
  26. /// Item whose details to show
  27. /// </summary>
  28. RSSItem item;
  29. /// <summary>
  30. /// Constructor
  31. /// </summary>
  32. public ItemPage()
  33. {
  34. InitializeComponent();
  35. Loaded += ItemPage_Loaded;
  36. }
  37. /// <summary>
  38. /// Overridden OnNavigatedTo handler
  39. /// </summary>
  40. protected override void OnNavigatedTo(NavigationEventArgs e)
  41. {
  42. base.OnNavigatedTo(e);
  43. if (isNewInstance)
  44. {
  45. if( State.ContainsKey( "CurrentItem" ) )
  46. {
  47. item = (RSSItem)State["CurrentItem"];
  48. }
  49. else
  50. {
  51. item = RSSService.SelectedItem;
  52. }
  53. isNewInstance = false;
  54. }
  55. }
  56. /// <summary>
  57. /// Overridden OnNavigatedFrom handler
  58. /// </summary>
  59. protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
  60. {
  61. if (e.NavigationMode != NavigationMode.Back)
  62. {
  63. State["CurrentItem"] = item;
  64. }
  65. }
  66. /// <summary>
  67. /// Handler for showing RSS item details when view is ready for it
  68. /// </summary>
  69. private void ItemPage_Loaded(object sender, RoutedEventArgs e)
  70. {
  71. browser.Navigated += ArticleWebBrowser_Navigated;
  72. if (item.Text != null)
  73. {
  74. browser.NavigateToString(RSSService.CreateArticleHTML(item));
  75. }
  76. }
  77. /// <summary>
  78. /// Sets the WebBrowser visible after the content has been loaded,
  79. /// to prevent the white flicker of empty WebBrowser that still loads it's content
  80. /// </summary>-
  81. private void ArticleWebBrowser_Navigated(object sender, NavigationEventArgs e)
  82. {
  83. browser.Visibility = Visibility.Visible;
  84. }
  85. /// <summary>
  86. /// Handler for launch button
  87. /// </summary>
  88. private void LaunchInBrowser(object sender, EventArgs e)
  89. {
  90. WebBrowserTask task = new WebBrowserTask();
  91. task.Uri = new Uri( item.Url, UriKind.RelativeOrAbsolute);
  92. task.Show();
  93. }
  94. }
  95. }