LoginSignup
1
2

More than 5 years have passed since last update.

WPFでDataGridのスクロールバーのパラメーターを取得

Last updated at Posted at 2018-06-04

WPFでDataGridのメソッドからScrollChangedのイベントが取れない。
なので、VisualTreeHelperクラスを使って、親クラスから辿って取得した。

DataGridのイベントでアタッチ

protected override void OnAttached()
{
  base.OnAttached();
  this.AssociatedObject.LoadingRow += this.AssociatedObjectUnloadingRow;
}

ScrollChangedを取得

どのイベントで取得するかは、用途により変更してください。
今回は行の読み込みイベントで行っている。

private void AssociatedObjectUnloadingRow(object sender, DataGridRowEventArgs e)
{
  Decorator child = VisualTreeHelper.GetChild(AssociatedObject, 0) as Decorator;
  ScrollViewer childSV = child.Child as ScrollViewer;
  childSV.ScrollChanged += new ScrollChangedEventHandler(DataGrid_ScrollChanged);
}

これで、パラメーター取得できる。
あとは、スクロールバーの変化量取得したり・・最下層に移動したり・・・

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2