, , . . usecase, DraggableListBox. , ListBox.
, ListItem:
public static class WpfDomHelper
{
public static T FindParent<T>(this DependencyObject child) where T : DependencyObject
{
DependencyObject parentObject = VisualTreeHelper.GetParent(child);
if (parentObject == null) return null;
T parent = parentObject as T;
if (parent != null)
return parent;
else
return FindParent<T>(parentObject);
}
}
Drop-, () Drop Y ListBoxItems:
private void Grid_Drop(object sender, DragEventArgs e)
{
int dropIndex = -1;
Point pt = e.GetPosition((UIElement)sender);
HitTestResult result = VisualTreeHelper.HitTest(this, pt);
if (result != null && result.VisualHit != null)
{
var theOne = result.VisualHit.FindParent<Microsoft.TeamFoundation.Controls.WPF.DraggableListBoxItem>();
if (theOne != null)
{
var itemCenterPosY = theOne.ActualHeight / 2;
var dropPosInItemPos = e.GetPosition(theOne);
var itemIndex = tasksListBox.Items.IndexOf(theOne.Content);
if (dropPosInItemPos.Y > itemCenterPosY)
{
itemIndex = itemIndex + 1;
}
dropIndex = itemIndex;
}
}
.... here create the item .....
if (dropIndex < 0)
ViewModel.Items.Add(item);
else
ViewModel.Items.Insert(dropIndex, item);
e.Handled = true;
}
So this solution works with my DraggableListBoxView template, I believe that the same solution should work with the standard ListBoxView. Good luck
source
share