Hi I have a xamDataGrid which i got drag and drop enabled so the user can reorder the rows. But the problem is that if i resize the data grid so that horizontal or vertical scrollbar appears, and if i have a record row selected in the grid, when i drag the scroll bar the mouse move will also trigger the reordering.
How can i disable the drag and drop behavior if I just want to drag the scroll bar?
Or is there a way to determine that the mouse click is on the scroll bar? thanks.
When you start dragging you can check the e.OriginalSource or its visual ancestors and see if you have clicked on a scrollbar or not.
e.OriginalSource is detecting the scroll bar. That works fine.
I have another issue though. the datagrid header is also invoking the drag and drop and the e.OriginalSource seems cannot differentiate the header drag and the content drag. Any ideas? Thanks.
You would have to check the type of the record on the mouse down event. You probably want to start dragging only on DataRecords. You can do that by traversing the visual tree, starting from the e.OriginalSource and look in the ancestor chain of elements.
Thanks. but I looked into e.OriginalSource base and couldn't find a way to traverse the visual tree. There's no ancestor or things like that property available there. What did I miss?
You can try something like this:
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter;
if(drp!=null && drp.Record.RecodType==....)
....
I used your code but drp will always return me null no matter if I dragged the header or the record itself. Any ideas?
i see the problem. I have to handle this event in the
PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
event handler, i am currently handing this in
PreviewMouseMove(object sender, MouseEventArgs e)
event handler. And apparently the e is different in the two event handlers.
I can now differentiate drag header now. but i am still having issue to resizing the columns. If i have an active record and trying to resize the columns, the drag and drop is again being invoked. I noticed that the resizing of the columns will not trigger the
event handler. What should I do to resolve this? thanks.
Update: i have opened a new thread on this issue. Thanks.
http://forums.infragistics.com/forums/p/39427/223810.aspx#223810