private static void Drop(object sender, DragAndDropEventArgs <SavedTemplateViewModel> e)
        {
            if (_getSavedPages().Count > 0 && _getSavedPages().Count >= e.ItemData.GenGroup + 1)
            {
                var items = _getSavedPages()[e.ItemData.GenGroup];
                if (items.Count > 1)
                {
                    if (e.NewIndex == 0)
                    {
                        _setHome(e.ItemData);
                    }

                    if (e.OldIndex > -1)
                    {
                        _getSavedPages()[e.ItemData.GenGroup].Move(e.OldIndex, e.NewIndex);
                    }

                    _setHome(items.First());
                }
            }
        }
Example #2
0
        private void OnDrop(object sender, DragEventArgs e)
        {
            if (ItemUnderDragCursor != null)
            {
                ItemUnderDragCursor = null;
            }

            e.Effects = DragDropEffects.None;

            if (e.Data.GetDataPresent(typeof(T)))
            {
                // Get the data dropped object.
                T data = e.Data.GetData(typeof(T)) as T;
                if (data != null)
                {
                    var itemsSource = this._listView.ItemsSource as ObservableCollection <T>;
                    if (itemsSource != null)
                    {
                        int oldIndex = itemsSource.IndexOf(data);
                        int newIndex = GetIndexUnderDragCursor();

                        if (newIndex < 0)
                        {
                            if (itemsSource.Count == 0)
                            {
                                newIndex = 0;
                            }
                            else if (oldIndex < 0)
                            {
                                newIndex = itemsSource.Count;
                            }
                            else
                            {
                                return;
                            }
                        }

                        if (oldIndex != newIndex)
                        {
                            if (ProcessDrop != null)
                            {
                                // Let the wizard process the drop.
                                DragAndDropEventArgs <T> args = new DragAndDropEventArgs <T>(itemsSource, data, oldIndex, newIndex, e.AllowedEffects);
                                ProcessDrop(this, args);
                                e.Effects = args.Effects;
                            }
                            else
                            {
                                if (oldIndex > -1)
                                {
                                    itemsSource.Move(oldIndex, newIndex);
                                }
                                else
                                {
                                    itemsSource.Insert(newIndex, data);
                                }
                                e.Effects = DragDropEffects.Move;
                            }
                        }
                    }
                }
            }
        }