BasePage.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.ComponentModel;
  4. using System.Threading.Tasks;
  5. using System.Web;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace MediaBrowser.UI.Pages
  9. {
  10. public abstract class BasePage : Page, INotifyPropertyChanged
  11. {
  12. public event PropertyChangedEventHandler PropertyChanged;
  13. public void OnPropertyChanged(String info)
  14. {
  15. if (PropertyChanged != null)
  16. {
  17. PropertyChanged(this, new PropertyChangedEventArgs(info));
  18. }
  19. }
  20. protected Uri Uri
  21. {
  22. get
  23. {
  24. return NavigationService.CurrentSource;
  25. }
  26. }
  27. protected MainWindow MainWindow
  28. {
  29. get
  30. {
  31. return App.Instance.MainWindow as MainWindow;
  32. }
  33. }
  34. private NameValueCollection _queryString;
  35. protected NameValueCollection QueryString
  36. {
  37. get
  38. {
  39. if (_queryString == null)
  40. {
  41. string url = Uri.ToString();
  42. int index = url.IndexOf('?');
  43. if (index == -1)
  44. {
  45. _queryString = new NameValueCollection();
  46. }
  47. else
  48. {
  49. _queryString = HttpUtility.ParseQueryString(url.Substring(index + 1));
  50. }
  51. }
  52. return _queryString;
  53. }
  54. }
  55. protected BasePage()
  56. : base()
  57. {
  58. Loaded += BasePageLoaded;
  59. }
  60. async void BasePageLoaded(object sender, RoutedEventArgs e)
  61. {
  62. await LoadData();
  63. DataContext = this;
  64. }
  65. protected abstract Task LoadData();
  66. }
  67. }