2016-05-26 1 views
-1

私はデータグリッドを持っていますが、これはXMLファイルでロードされています...問題ありません。クリックドラッグでDataGridをスクロール

ユーザーがすべてのDataGridをドラッグするときはスクロールを許可するか、行を選択して上下にドラッグしてコンテンツをスクロールする必要があります。 私はスクロールバーを持っていますが、このアプリはタッチスクリーン用ですので、スクロールするDataGridをより簡単にドラッグできます。

おかげで...

答えて

0

このトリックを行う必要があります。 を処理し、イベントのDataGridをドラッグし、プログラムによってデータグリッドをスクロールします。

// hook up the row events during the loading row event for the datagrid 
    private void MyDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) 
    { 
     e.Row.DragOver += new DragEventHandler(MyRow_DragOver); 
     e.Row.Drop += new DragEventHandler(MyRow_Drop); 
    } 

    private void MyRow_DragOver(object sender, DragEventArgs e) 
    { 
     DataGridRow r = (DataGridRow)sender; 
     MyDataGrid.SelectedItem = r.Item; 

     // Scroll while dragging... 
     DependencyObject d = MyDataGrid; 
     while (!(d is ScrollViewer)) 
     { 
      d = VisualTreeHelper.GetChild(d, 0); 
     } 
     ScrollViewer scroll = d as ScrollViewer; 

     Point position = MyDataGrid.PointToScreen(Mouse.GetPosition(r)); 

     // create this textbox to test in real time the value of gridOrigin 
     textBox1.Text = position.ToString(); 

     double topMargin = scroll.ActualHeight * .15; 
     double bottomMargin = scroll.ActualHeight * .80; 

     if (position.Y * -1 < topMargin) 
     scroll.LineUp(); // <-- needs a mechanism to control the speed of the scroll. 
     if (position.Y * -1 > bottomMargin) 
     scroll.LineDown(); // <-- needs a mechanism to control the speed of the scroll. 
    } 
+0

あなたは 'MyRow_Drop'ですか? –

関連する問題