BasePage.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using MediaBrowser.Model.Dto;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. namespace MediaBrowser.UI.Pages
  8. {
  9. /// <summary>
  10. /// Provides a common base page for all pages
  11. /// </summary>
  12. public abstract class BasePage : Page, INotifyPropertyChanged
  13. {
  14. public event PropertyChangedEventHandler PropertyChanged;
  15. public virtual void OnPropertyChanged(string name)
  16. {
  17. if (PropertyChanged != null)
  18. {
  19. PropertyChanged(this, new PropertyChangedEventArgs(name));
  20. }
  21. }
  22. protected override void OnInitialized(EventArgs e)
  23. {
  24. Loaded += BasePageLoaded;
  25. Unloaded += BasePage_Unloaded;
  26. base.OnInitialized(e);
  27. DataContext = this;
  28. }
  29. void BasePage_Unloaded(object sender, RoutedEventArgs e)
  30. {
  31. OnUnloaded();
  32. }
  33. void BasePageLoaded(object sender, RoutedEventArgs e)
  34. {
  35. OnLoaded();
  36. }
  37. protected virtual void OnLoaded()
  38. {
  39. // Give focus to the first element
  40. MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
  41. }
  42. protected virtual void OnUnloaded()
  43. {
  44. }
  45. /// <summary>
  46. /// Sets the backdrop based on a BaseItemDto
  47. /// </summary>
  48. public void SetBackdrops(BaseItemDto item)
  49. {
  50. App.Instance.ApplicationWindow.SetBackdrops(item);
  51. }
  52. /// <summary>
  53. /// Clears current backdrops
  54. /// </summary>
  55. public void ClearBackdrops()
  56. {
  57. App.Instance.ApplicationWindow.ClearBackdrops();
  58. }
  59. }
  60. }