aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.UI/Pages/BasePage.cs
blob: 667a29ff370efbb440e466d9e585c972985b27ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 BaseItemDto
        /// </summary>
        public void SetBackdrops(BaseItemDto item)
        {
            App.Instance.ApplicationWindow.SetBackdrops(item);
        }

        /// <summary>
        /// Clears current backdrops
        /// </summary>
        public void ClearBackdrops()
        {
            App.Instance.ApplicationWindow.ClearBackdrops();
        }
    }
}