我在它周围的滚动查看器中有一个文本块。我的应用程序完全由遥控器控制,因此在这种情况下,导航是通过向上、向下、向左和向右键执行的。
我可以导航到文本块,但后来我被困在那里。我已经尝试将 KeyboardNavigation.DirectionalNavigation="Continue" 放在每个控件中,但没有任何乐趣。
然后我想制作一个扩展滚动条或滚动查看器的自定义控件。如果扩展滚动条,我可以按以下方式覆盖 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 代码中?