From 85603eae41c49ad1cc9e0ee0890918b19b369a22 Mon Sep 17 00:00:00 2001 From: Melissa Geels Date: Sat, 17 Jan 2026 12:56:02 +0100 Subject: [PATCH 1/2] Added arrow key scroll navigation to ScrollViewer control --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 38 ++++++++++++++++--- src/Avalonia.Controls/ScrollViewer.cs | 20 ++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 7df7012f8f..0aae6f80da 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -245,15 +245,41 @@ namespace Avalonia.Controls.Primitives protected override void OnKeyDown(KeyEventArgs e) { - if (e.Key == Key.PageUp) + if (Orientation == Orientation.Vertical) { - LargeDecrement(); - e.Handled = true; + if (e.Key == Key.PageUp) + { + LargeDecrement(); + e.Handled = true; + } + else if (e.Key == Key.PageDown) + { + LargeIncrement(); + e.Handled = true; + } + else if (e.Key == Key.Up) + { + SmallDecrement(); + e.Handled = true; + } + else if (e.Key == Key.Down) + { + SmallIncrement(); + e.Handled = true; + } } - else if (e.Key == Key.PageDown) + else if (Orientation == Orientation.Horizontal) { - LargeIncrement(); - e.Handled = true; + if (e.Key == Key.Left) + { + SmallDecrement(); + e.Handled = true; + } + else if (e.Key == Key.Right) + { + SmallIncrement(); + e.Handled = true; + } } } diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index 3152eec2db..ceef8db13f 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -786,6 +786,26 @@ namespace Avalonia.Controls PageDown(); e.Handled = true; } + else if (e.Key == Key.Left) + { + LineLeft(); + e.Handled = true; + } + else if (e.Key == Key.Right) + { + LineRight(); + e.Handled = true; + } + else if (e.Key == Key.Up) + { + LineUp(); + e.Handled = true; + } + else if (e.Key == Key.Down) + { + LineDown(); + e.Handled = true; + } } /// From f7b05b7171de042683c1ad717063a8d3b4efaca6 Mon Sep 17 00:00:00 2001 From: Melissa Geels Date: Thu, 22 Jan 2026 11:57:15 +0100 Subject: [PATCH 2/2] Check event source before handling Left/Right/Up/Down keys --- src/Avalonia.Controls/ScrollViewer.cs | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index ceef8db13f..35b3adef38 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -786,25 +786,28 @@ namespace Avalonia.Controls PageDown(); e.Handled = true; } - else if (e.Key == Key.Left) + else if (e.Source == this) { - LineLeft(); - e.Handled = true; - } - else if (e.Key == Key.Right) - { - LineRight(); - e.Handled = true; - } - else if (e.Key == Key.Up) - { - LineUp(); - e.Handled = true; - } - else if (e.Key == Key.Down) - { - LineDown(); - e.Handled = true; + if (e.Key == Key.Left) + { + LineLeft(); + e.Handled = true; + } + else if (e.Key == Key.Right) + { + LineRight(); + e.Handled = true; + } + else if (e.Key == Key.Up) + { + LineUp(); + e.Handled = true; + } + else if (e.Key == Key.Down) + { + LineDown(); + e.Handled = true; + } } }