Browse Source
This is a temporary workaround to #30 - it's very hacky: - Tab key handling is built into TextBox - all other controls don't work. It needs to be moved into InputElement. - It only traverses siblings. - Setting focus to template children is a hack. - Many more problems.pull/39/head
5 changed files with 84 additions and 0 deletions
@ -0,0 +1,49 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="FocusNavigationDirection.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.VisualTree; |
|||
|
|||
/// <summary>
|
|||
/// TODO: This class is a temporary stop-gap just to add tab handling. Should be replaced
|
|||
/// with something better thought out and testable etc.
|
|||
/// </summary>
|
|||
public static class KeyboardNavigation |
|||
{ |
|||
public static void MoveNext(IInputElement element) |
|||
{ |
|||
var siblings = element.GetVisualSiblings().OfType<IInputElement>() |
|||
.Where(x => x.Focusable) |
|||
.SkipWhile(x => x != element) |
|||
.Skip(1); |
|||
|
|||
var next = siblings.FirstOrDefault(); |
|||
|
|||
if (next != null) |
|||
{ |
|||
FocusManager.Instance.Focus(next); |
|||
} |
|||
} |
|||
|
|||
public static void MovePrevious(IInputElement element) |
|||
{ |
|||
var siblings = element.GetVisualSiblings().OfType<IInputElement>() |
|||
.Where(x => x.Focusable) |
|||
.Reverse() |
|||
.SkipWhile(x => x != element) |
|||
.Skip(1); |
|||
|
|||
var next = siblings.FirstOrDefault(); |
|||
|
|||
if (next != null) |
|||
{ |
|||
FocusManager.Instance.Focus(next); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue