VisualTree
経由でコントロールのボタンを取得し、そのクリックイベントにハンドラをアタッチすることができます。
編集:私はパスを介してビジュアルツリーのアイテムを取得するための拡張メソッドを書いた:
public static class ExtensionMethods
{
public static DependencyObject GetVisualChildFromTreePath(this DependencyObject dpo, int[] path)
{
if (path.Length == 0) return dpo;
List<int> newPath = new List<int>(path);
newPath.RemoveAt(0);
return VisualTreeHelper.GetChild(dpo, path[0]).GetVisualChildFromTreePath(newPath.ToArray());
}
}
あなたは、このようなボタンを取得することができるはずSVあなたScrollViewer
が呼び出された場合:
RepeatButton button1 = sv.GetVisualChildFromTreePath(new int[] { 0, 2, 0, 0 }) as RepeatButton; //Up
RepeatButton button2 = sv.GetVisualChildFromTreePath(new int[] { 0, 2, 0, 2 }) as RepeatButton; //Down
RepeatButton button3 = sv.GetVisualChildFromTreePath(new int[] { 0, 3, 0, 0 }) as RepeatButton; //Left
RepeatButton button4 = sv.GetVisualChildFromTreePath(new int[] { 0, 3, 0, 2 }) as RepeatButton; //Right
注:ボタンは、それぞれのスクロールバーが有効になっている場合にのみ存在します。拡張メソッドは、おそらく他のデータ型を使用することによってパフォーマンスの面で改善される可能性があります。
ありがとうございます。私はHorizontal ScrollBar(一度初期化された)を見つけ、次にこれから適切なコマンド(LineRight)を持つボタンを見つけたScrollViewers Loadedイベントにハンドラを追加しました。その後、Clickイベントにハンドラを追加すると完全に動作します。 – sebf