private async void dragMgr_ProcessDrop(object sender, ProcessDropEventArgs <AnimationRigidBody> 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) && (e.DataItem.Name == null)) { var name = await this.ShowInputAsync("Name", "Please specify unique animator name or hit cancel!"); //await this.ShowMessageAsync("Hello", "Hello " + result + "!"); //var sobj= new SpriteObject(txtSpriteName.Text); Debug.WriteLine("=> item = {0} {1}", e.DataItem.GetType().Name, e.DataItem.Name); AnimationRigidBody ani = Activator.CreateInstance(e.DataItem.GetType()) as AnimationRigidBody; ani.Name = name; (GObj as SpriteObject).AddAnimation(ani); // generates unique name if name==null AList.Add(ani); //lstAnimations.Items.Refresh(); // Resize Columns var gridView = lstAnimations.View as GridView; foreach (var column in gridView.Columns.Where(column => Double.IsNaN(column.Width))) { Contract.Assume(column != null); column.Width = column.ActualWidth; column.Width = Double.NaN; } // 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); // update Sprite animation list (GObj as SpriteObject).SerializableAnimations = AList; } // Set this to 'Move' so that the OnListViewDrop knows to // remove the item from the other ListView. e.Effects = System.Windows.DragDropEffects.Move; }
private void lstAnimations_KeyDown(object sender, KeyEventArgs e) { AnimationRigidBody obj = (lstAnimations.SelectedItem as AnimationRigidBody); if (obj != null) { if (e.Key == Key.Delete) { AList.Remove(obj); (GObj as SpriteObject).RemoveAnimation(obj); } } }