Esempio n. 1
0
        //private void lstSprites_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    // Store the mouse position
        //    dragDropPoint = e.GetPosition(null);
        //}

        //private void lstSprites_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        //{
        //    Point pos = e.GetPosition(null);
        //    Vector diff = dragDropPoint - pos;

        //    if (e.LeftButton == MouseButtonState.Pressed &&
        //       ( Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
        //        Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
        //    {
        //        // Get dragged item
        //        System.Windows.Controls.ListView listView = sender as System.Windows.Controls.ListView;
        //        var listViewItem =
        //            FindAnchestor<System.Windows.Controls.ListViewItem>((DependencyObject)e.OriginalSource);

        //        // Find the data behind the ListViewItem
        //        SpriteObject sprite = listView.ItemContainerGenerator.ItemFromContainer(listViewItem) as SpriteObject;

        //        // Initialize the drag & drop operation
        //        System.Windows.DataObject dragData = new System.Windows.DataObject("SpriteObject", sprite );
        //        DragDrop.DoDragDrop(listViewItem, dragData, System.Windows.DragDropEffects.Move);
        //    }
        //}

        //private static T FindAnchestor<T>(DependencyObject current)
        //    where T : DependencyObject
        //{
        //    do
        //    {
        //        if (current is T)
        //        {
        //            return (T)current;
        //        }
        //        current = VisualTreeHelper.GetParent(current);
        //    }
        //    while (current != null);
        //    return null;
        //}

        void dragMgr_ProcessDrop(object sender, ProcessDropEventArgs <IGameObject> e)
        {
            // This shows how to customize the behavior of a drop.
            // Here we perform a swap, instead of just moving the dropped item.
            int higherIdx = Math.Max(e.OldIndex, e.NewIndex);
            int lowerIdx  = Math.Min(e.OldIndex, e.NewIndex);

            if (lowerIdx < 0)
            {
                Debug.WriteLine("=> item = {0} {1}", lowerIdx, sender.GetType().Name);
                // The item came from the lower ListView
                // so just insert it.
                //e.ItemsSource.Insert(higherIdx, e.DataItem);
            }
            else
            {
                // null values will cause an error when calling Move.
                // It looks like a bug in ObservableCollection to me.
                if (e.ItemsSource[lowerIdx] == null ||
                    e.ItemsSource[higherIdx] == null)
                {
                    return;
                }

                // The item came from the ListView into which
                // it was dropped, so swap it with the item
                // at the target index.
                e.ItemsSource.Move(lowerIdx, higherIdx);
                e.ItemsSource.Move(higherIdx - 1, lowerIdx);
            }

            // Set this to 'Move' so that the OnListViewDrop knows to
            // remove the item from the other ListView.
            e.Effects = System.Windows.DragDropEffects.Move;
            ThisLevel.RemoveSpritesFrom(MainGFX);
            ThisLevel.AddSpritesTo(MainGFX);
        }