0
我在它周围的滚动查看器中有一个Textblock。我的应用程序完全由远程控制,所以在这种情况下,导航使用键上,下,左和右进行。ScrollViewer中的键盘导航TextBlock
我可以导航到文本块,但然后我被困在那里。我已经尝试在每个控件中放置KeyboardNavigation.DirectionalNavigation =“Continue”,但我无法享受。
然后我想到做一个自定义控件来扩展滚动条或scrollviewer。 如果扩展滚动条,我可以按照以下方式覆盖keydown。
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
if (this.Orientation == Orientation.Vertical)
{
if (e.Key == Key.Up)
{
if (this.Value == this.Minimum)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
e.Handled = true;
}
}
if (e.Key == Key.Down)
{
if (this.Value == this.Maximum)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
e.Handled = true;
}
}
if (e.Key == Key.Left)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
e.Handled = true;
}
if (e.Key == Key.Right)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
e.Handled = true;
}
}
if (this.Orientation == Orientation.Horizontal)
{
if (e.Key == Key.Left)
{
if (this.Value == this.Minimum)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
e.Handled = true;
}
}
if (e.Key == Key.Right)
{
if (this.Value == this.Maximum)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
e.Handled = true;
}
}
if (e.Key == Key.Up)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
e.Handled = true;
}
if (e.Key == Key.Down)
{
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
e.Handled = true;
}
}
base.OnPreviewKeyDown(e);
}
}
的问题是我不知道如何改变的ScrollViewer滚动使用一个自定义或者即使当一个键被按下上面的代码会甚至引起火灾。我认为文本块和滚动查看器将成为查看事件的控件。
有没有办法做类似于上面的代码,但在Scrollviewers代码后面?
如果您处于文本块下的控件(称为控件A),并按下向上键,则文本块将获得焦点。现在向上或向下按可以上下滚动文本,但是永远不能使用键盘将焦点从文本块移开(即使滚动查看器位于最下方,IE也会按下,不会使您返回到控制A)对于诸如文本框之类的控件,我们遇到了同样的问题,但是使用类似于上面的代码来解决它 – Oli