Hi,
I am trying to write a small framework of my own by wrapping (trying to) the infragistics DragDrop Framework in an attached behavior/ blend behavior.
The difference between the two is while attahced behavior is static blend behavior is instance based. Anyways, coming to the main topic.
I know the following things:
1) To make an UIElement drag source the following code is required. I am fine with this:
<ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" DragChannels="Animal,Human" Drop="DragSource_Drop"> </ig:DragSource> </ig:DragDropManager.DragSource>
2) To make an UIElement a drop target the following code is required. I am fine with this too:
<ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True" DropChannels="Animal"/> </ig:DragDropManager.DropTarget>
3) In the code behind, add the following handler:
private void DragSource_Drop(object sender, Infragistics.DragDrop.DropEventArgs e) { }
This is a spoiler. as this adds code behind. So I went for attahced behavior. Also, why not take the data required in the drag drop operations frm the ViewModel classes. This will give ViewModel s more control of the view. This idea made me create a couple of interfaces called IDragSource and IDropTarget that would contain all the info required for dragdrop operation.
So here goes my code, inside the behavior class:
var dragSource = AssociatedObject.DataContext as IDragSource; if (null != dragSource) { var infragisticsDragSource = new DragSource() { IsDraggable = dragSource.IsDraggable, DragChannels = dragSource.DragChannels }; infragisticsDragSource.Drop += DragSource_Drop; DragDropManager.SetDragSource(AssociatedObject, infragisticsDragSource); }
var dropTarget = AssociatedObject.DataContext as IDropTarget; if (null != dropTarget) { var infragisticsDropTarget = new DropTarget() { DropChannels = dropTarget.DropChannels, IsDropTarget = dropTarget.IsDropTarget }; }
Clearly, I have the Drop handler in the behavior clas itself:
private void DragSource_Drop(object sender, DropEventArgs e) { foreach (FrameworkElement fe in e.DropTargetElements) { var dropTarget = fe.DataContext as IDropTarget; if (sender is IDragSource) dropTarget.OnDropped((sender as IDragSource).DropArgument); } }
I just cant make it work. Is it some silly mistake I am doing or something being overlooked by me. I have attached the demo application. Please note you will need System.Windows.Interactivity.dll for the blend behavior to work. If you hate blend, just remove that class from the project. No problem. I am fine with the attached behavior way too.
regards,
Hello Sid,
If I have understand your scenario correctly, you need to apply the drag and drop functionality on the record selector (the small arrow on the left side of the record) so the user can drag and drop a record by dragging and dropping the selector. After researching this further I could say that currently the XamDataGrid control does not support this functionality. The Drag and Drop framework is working on editable items – DataRecordPresenter and CellValuePresenter, in other words where both KeyDown and PreviewKeyDown events are not handled internally. Speaking of the record selector these events are handled so that the basic functionality of the grid, such as selection, is working as expected. Please note that you may use our site for product ideas http://ideas.infragistics.com and suggest this functionality to be included.
Steps to create your idea:
The benefits of submitting the product idea yourself include:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
Additional benefits of the Product Idea system include:
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
The product ideas site allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Hello Maria,
Thank you for your reply. It is working good. I want another small insight, this time not really about hte drag drop framework, but about the styling that needs to be in place. I want to use drag drop for reordering a grids row. Therefore for me the drag dource is the GridRow and Drop Targt is the grid itself. I downloaded a project from one of the forum questions and modified it to suit my needs of reordering. I also made it MVVM friendly by wrapping the drop logic in a behavior.However, I want to drag a row only by its header. I have put the drag drop properties in the DataRecordPresenter style. I am able to drag the row by its body (not covered by cell area) how to enable dragging by row header. I am attaching the sample project.
Please note you will need System.Windows.Interactivity for the blend behavior I have used.
Thank you for contacting our community!
I have been looking into your sample project and modified it so that the user can drag and drop items to the ListBox controls on the right side. There are a couple of changes to be made so that the sample works as expected. In the DragDropAttached class the DragSource had been correctly set: DragDropManager.SetDragSource(item, infragisticsDragSource); The same should be done for the DropTarget, too. Otherwise the framework would not know where to put the item: DragDropManager.SetDropTarget(item, infragisticsDropTarget);
Another thing to notice is that the element could not be directly cast to IDragSource. The FrameworkElement’s DataContext can be used to get the IDragSource object.
private static void DragSource_Drop(object sender, DropEventArgs e)
{
foreach (FrameworkElement fe in e.DropTargetElements)
var dropTarget = fe.DataContext as IDropTarget;
FrameworkElement dropElement = (sender as DragSource).AssociatedObject as FrameworkElement;
if (dropElement != null && dropElement.DataContext is IDragSource)
dropTarget.OnDropped((dropElement.DataContext as IDragSource).DropArgument);
}
Please feel free to test the attached project and let me know if you have any questions or concerns.
Anybody got a chance to look into this?