私はその周りのスクロールビューア内にTextblockを持っています。私のアプリケーションは完全にリモートで制御されるので、このコンテキストではナビゲーションはキーの上下左右で実行されます。ScrollViewerのキーボードナビゲーション
私はTextblockにナビゲートできますが、そこにトラップされます。私はKeyboardNavigation.DirectionalNavigationを配置しようとしました=すべてのコントロールで "続ける"ことができますが、喜びはありません。
次に、スクロールバーまたはスクロールバーを拡張するカスタムコントロールを作成することを考えました。 スクロールバーを拡張する場合は、以下のように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のスクロールバーを変更するかどうかはわかりませんで、またはいずれかのキーが押されたとき、上記のコードでも発火する場合でも。私はテキストブロックを想定し、scrollviewerはイベントを見るコントロールになります。
上記のコードと似たような方法がありますか?Scrollviewersコードの背後にありますか?
あなたがコントロールしている場合は、テキストブロックがフォーカスを取得するテキストブロックの下にあり、アップキーを押してください(コントロールAそれを呼びましょう)。上または下を押すとテキストが上下にスクロールしますが、キーボードでテキストブロックからフォーカスを移動することは決してできません(IEはスクロールビューアが一番下にあっても押し下げてもコントロールAに戻りません)テキストボックスなどのオーバーコントロールでも同じ問題がありましたが、上記と同様のコードを使用して回避します – Oli