aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.UI.Controls/ExtendedScrollViewer.cs
blob: c1a6f1c4782615fdde4882211e5222446b72af02 (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
using System.Windows.Controls;
using System.Windows.Input;

namespace MediaBrowser.UI.Controls
{
    /// <summary>
    /// This subclass solves the problem of ScrollViewers eating KeyDown for all arrow keys
    /// </summary>
    public class ExtendedScrollViewer : ScrollViewer
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Handled || e.OriginalSource == this)
            {
                base.OnKeyDown(e);
                return;
            } 
            
            // Don't eat left/right if horizontal scrolling is disabled
            if (e.Key == Key.Left || e.Key == Key.Right)
            {
                if (HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled)
                {
                    return;
                }
            }

            // Don't eat up/down if vertical scrolling is disabled
            if (e.Key == Key.Up || e.Key == Key.Down)
            {
                if (VerticalScrollBarVisibility == ScrollBarVisibility.Disabled)
                {
                    return;
                }
            }

            // Let the base class do it's thing
            base.OnKeyDown(e);
        }
    }
}