private void listBoxItem_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) { if (dragGhost != null) { var p = NativeMethods.GetNowPosition(this); var loc = this.PointFromScreen(StoryFrameList.PointToScreen(new Point(0, 0))); dragGhost.LeftOffset = p.X - loc.X; dragGhost.TopOffset = p.Y - loc.Y; } }
private void listBox_Drop(object sender, DragEventArgs e) { var dropPos = e.GetPosition(StoryFrameList); var lbi = e.Data.GetData(typeof(ListBoxItem)) as ListBoxItem; var o = lbi.DataContext as IMarkable; var index = _model.StoryFrameModelCollection.IndexOf(o); for (int i = 0; i < _model.StoryFrameModelCollection.Count; i++) { var item = StoryFrameList.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem; var pos = StoryFrameList.PointFromScreen(item.PointToScreen(new Point(0, item.ActualHeight / 2))); if (dropPos.Y < pos.Y) { // i が入れ換え先のインデックス _model.MoveCollection(index, (index < i) ? i - 1 : i); return; } } // 最後にもっていく int last = _model.StoryFrameModelCollection.Count - 1; _model.MoveCollection(index, last); }