aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.UI/Pages/BasePage.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.UI/Pages/BasePage.cs')
-rw-r--r--MediaBrowser.UI/Pages/BasePage.cs150
1 files changed, 71 insertions, 79 deletions
diff --git a/MediaBrowser.UI/Pages/BasePage.cs b/MediaBrowser.UI/Pages/BasePage.cs
index 800f6e215..c07c194c6 100644
--- a/MediaBrowser.UI/Pages/BasePage.cs
+++ b/MediaBrowser.UI/Pages/BasePage.cs
@@ -1,79 +1,71 @@
-using System;
-using System.Collections.Specialized;
-using System.ComponentModel;
-using System.Threading.Tasks;
-using System.Web;
-using System.Windows;
-using System.Windows.Controls;
-
-namespace MediaBrowser.UI.Pages
-{
- public abstract class BasePage : Page, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
-
- public void OnPropertyChanged(String info)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(info));
- }
- }
-
- protected Uri Uri
- {
- get
- {
- return NavigationService.CurrentSource;
- }
- }
-
- protected MainWindow MainWindow
- {
- get
- {
- return App.Instance.MainWindow as MainWindow;
- }
- }
-
- private NameValueCollection _queryString;
- protected NameValueCollection QueryString
- {
- get
- {
- if (_queryString == null)
- {
- string url = Uri.ToString();
-
- int index = url.IndexOf('?');
-
- if (index == -1)
- {
- _queryString = new NameValueCollection();
- }
- else
- {
- _queryString = HttpUtility.ParseQueryString(url.Substring(index + 1));
- }
- }
-
- return _queryString;
- }
- }
-
- protected BasePage()
- : base()
- {
- Loaded += BasePageLoaded;
- }
-
- async void BasePageLoaded(object sender, RoutedEventArgs e)
- {
- await LoadData();
-
- DataContext = this;
- }
-
- protected abstract Task LoadData();
- }
-}
+using MediaBrowser.Model.DTO;
+using System;
+using System.ComponentModel;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace MediaBrowser.UI.Pages
+{
+ /// <summary>
+ /// Provides a common base page for all pages
+ /// </summary>
+ public abstract class BasePage : Page, INotifyPropertyChanged
+ {
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public virtual void OnPropertyChanged(string name)
+ {
+ if (PropertyChanged != null)
+ {
+ PropertyChanged(this, new PropertyChangedEventArgs(name));
+ }
+ }
+
+ protected override void OnInitialized(EventArgs e)
+ {
+ Loaded += BasePageLoaded;
+ Unloaded += BasePage_Unloaded;
+
+ base.OnInitialized(e);
+
+ DataContext = this;
+ }
+
+ void BasePage_Unloaded(object sender, RoutedEventArgs e)
+ {
+ OnUnloaded();
+ }
+
+ void BasePageLoaded(object sender, RoutedEventArgs e)
+ {
+ OnLoaded();
+ }
+
+ protected virtual void OnLoaded()
+ {
+ // Give focus to the first element
+ MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
+ }
+
+ protected virtual void OnUnloaded()
+ {
+ }
+
+ /// <summary>
+ /// Sets the backdrop based on a DtoBaseItem
+ /// </summary>
+ public void SetBackdrops(DtoBaseItem item)
+ {
+ App.Instance.ApplicationWindow.SetBackdrops(item);
+ }
+
+ /// <summary>
+ /// Clears current backdrops
+ /// </summary>
+ public void ClearBackdrops()
+ {
+ App.Instance.ApplicationWindow.ClearBackdrops();
+ }
+ }
+}