Hello,
Thanks for the zip file. They works fine with Q2 assemblies. The only thing is that they still use Style Resource "DraggableListBoxStyle" that I don' want to use.
I have put together a small applicatioin with Q2 dll and Drag/Drop events codes from one of your latest Example.cs files. I will appreciate if you fix my problem on this Application. Please search for the word "Problem" in the project and here I am not able to get the Index of dropped location. You may just have to change 2 or 3 lines of code.
I will really appreciate if you please make necessary changes so that I can
- Drop from one list box into other at desired location.
- Reorder the individual List box.
How can I send this project to you. I am not able to upload it. Only image files are enabled..
BTW here is the .DropInfo Event where I want the fix.
private void DropInfo(object sender, DragDropEventArgs e)
{
System.Windows.Controls.
ItemsControl wishlist = e.Options.Destination as System.Windows.Controls.ItemsControl;
ICollection draggedItems = e.Options.Payload as ICollection;
// Get the drag cu that the TreeView or we have created
TreeViewDragCue cue = e.Options.DragCue
as TreeViewDragCue;
if (e.Options.Status == DragStatus.DropPossible)
{
// Set a suitable text:
cue.DragActionContent =
String.Format("Add {0} item{1} to Wishlist", draggedItems.Count, draggedItems.Count > 1 ? "s" : String.Empty);
cue.IsDropPossible =
true;
// wishlist.Background = this.Resources["BasicBrush"] as Brush;
}
else if (e.Options.Status == DragStatus.DropImpossible)
{
cue.DragActionContent =
null;
cue.IsDropPossible =
false;
}
else if (e.Options.Status == DragStatus.DropComplete && e.Options.Destination is ListBox)
{
System.Windows.Controls.
ListBox listBoxSender = sender as System.Windows.Controls.ListBox;
IList items = wishlist.ItemsSource as IList;
IList<MachineScheduleViewModel> itemsSource = wishlist.ItemsSource as IList<MachineScheduleViewModel>;
foreach (object draggedItem in draggedItems)
{
//Problem
var destinationIndex = 2;// itemsSource.IndexOf((MachineScheduleViewModel)wishlist.DataContext);
var operation = draggedItem as DragDropOperation;
// var operation = e.Options.Payload as DragDropOperation;
//Problem here ****************************************************************************
// How can I get the actual insert Index... I have hard coded index = 2 and the dragged items are
// getting inserted there at idex 2.
var insertIndex =0;
if(itemsSource.Count > 2)
insertIndex = 2;
// operation.DropPosition == DropPosition.Before ? destinationIndex : destinationIndex + 1;
else
insertIndex = itemsSource.Count;
// Please fix this so that I can get the actual index ****************
itemsSource.Insert(insertIndex, (
MachineScheduleViewModel)draggedItem);
ListBox listBox = (ListBox)wishlist;
listBox.Dispatcher.BeginInvoke(() =>
{
listBox.SelectedIndex = insertIndex;
});
// items.Add(draggedItem); //original
}
}
if (e.Options.Status != DragStatus.DropPossible)
{
wishlist.Background =
new SolidColorBrush(Colors.White);
}
}