I am trying to create an application where I can drag and drop into either a Data Tree, list view, or stack panel.
I was hopping that when i drag an item into middle of the list of the one of those control. I would be able to reorder the list and add the item between those 2 items.
how can i tell what position the item is dropped into?
I got the drop event to file but i did not see any indication what position is drop too.
Thanks
Alan
Here is my code for the xmal
<Window x:Class="WpfTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ig="http://schemas.infragistics.com/xaml" mc:Ignorable="d">
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="200" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <WrapPanel Orientation ="Vertical" Grid.Column="0"> <Label Content="This is Action"/> <TextBlock Text="Test"> <ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" Drop ="DragSource_Drop" DragChannels="OnlyLocation"/> </ig:DragDropManager.DragSource> </TextBlock> <TextBlock Text="Test2"> <ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" Drop ="DragSource_Drop" DragChannels="OnlyLocation" /> </ig:DragDropManager.DragSource> </TextBlock> </WrapPanel> <ig:XamDataTree BorderThickness="1,1,1,1" Grid.Column="1" BorderBrush="Red" IsDraggable="True" IsDropTarget="True" Name="DataTree"> <ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True" DropChannels="OnlyLocation" /> </ig:DragDropManager.DropTarget> </ig:XamDataTree> </Grid></Window>
code-behind
using System;using System.Collections.Generic;using System.Windows.Controls;using Infragistics.DragDrop;
namespace WpfTest{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow { public MainWindow() { InitializeComponent(); DataTree.ItemsSource = GetData(); }
private System.Collections.IEnumerable GetData() { var testing = new List<string> { "testing", "tsting2" }; return testing; } private void DragSource_Drop(object sender, DropEventArgs e) { var testing = DragDropManager.GetDragSource(e.DragSource); }
//private void DragSource_DragStart(object sender, DragDropStartEventArgs e) //{ // if (e.OriginalDragSource is TextBlock) // { // e.DragSnapshotElement = e.OriginalDragSource; // } // else // { // e.Cancel = true; // } //}
//internal static void Testing(object sender, EventArgs e) //{ // var dragDropStartEventArgs = (DropEventArgs) e;
// var stackPanel = dragDropStartEventArgs.DropTarget as StackPanel;
// var testing = (Label) dragDropStartEventArgs.DragSource; // var tes = dragDropStartEventArgs.DropTargetElements;
//}
}
Hello Alan,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
I have created another sample for you with the functionality you want. This time I used the MS drag & drop, because the items that are going to be added in the StackPanel are new TextBlock and since the TextBlock doesn’t have Template it is not possible to make it DropTarget via Style. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Can this be easily apply to stack panel?
Thank you so much for your help
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I copied the default Style of the XamDataTreeNodeControl in order to make it a DropTarget. This way I was able to determine where exactly the text is being dropped, so I could insert it in the correct place in the collection. Please let me know if this helps you or you need further assistance on this matter.