protected override bool CanHandleData(object data)
        {
            var items = DefaultDropHandler.ExtractData(data)?.OfType <GiftItemModel>();

            return(items?.Any() == true && this.recipient.Gifts == null);
            //return base.CanHandle(dropInfo);
        }
 public override void Drop(IDropInfo dropInfo)
 {
     if (this.CanHandleData(dropInfo.Data))
     {
         this.recipient.Gifts = DefaultDropHandler.ExtractData(dropInfo.Data)?
                                .OfType <GiftItemModel>()
                                .ToList();
     }
 }
Example #3
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            if (!(dropInfo.VisualTarget is DataGrid))
            {
                return;
            }

            if (dropInfo.TargetGroup == null)
            {
                HandleEx(dropInfo);
                return;
            }

            int    target_posse_id;
            string target_group_name = dropInfo.TargetGroup.Name.ToString();

            if (Int32.TryParse(target_group_name, out target_posse_id))
            {
                var shooters           = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <Shooter>().ToList();
                var match_participants = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <MatchParticipation>().ToList();

                if ((shooters != null) && (shooters.Count > 0))
                {
                    foreach (Shooter s in shooters)
                    {
                        MatchParticipation mp = new MatchParticipation()
                        {
                            ShooterID = s.ShooterID,
                            MatchID   = _m.MatchID,
                            Posse     = (int)target_posse_id,
                            Category  = s.Category
                        };

                        _ctx.MatchParticipations.Attach(mp);

                        if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                        {
                            _ctx.MatchParticipations.Add(mp);
                        }

                        _ctx.SaveChanges();
                    }
                }
                else if ((match_participants != null) && (match_participants.Count > 0))
                {
                    foreach (MatchParticipation mp in match_participants)
                    {
                        _ctx.MatchParticipations.Where(x => x.MatchParticipationId.Equals(mp.MatchParticipationId)).First().Posse = (int)target_posse_id;
                    }

                    _ctx.SaveChanges();
                }

                Refresh();
            }
        }
Example #4
0
        public void Drop(IDropInfo dropInfo)
        {
            // The default drop handler don't know how to set an item's group. You need to explicitly set the group on the dropped item like this.
            GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.Drop(dropInfo);

            // Now extract the dragged group items and set the new group (target)
            System.Collections.Generic.List <PlusPropertyDescriptor> data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <PlusPropertyDescriptor>().ToList();
            foreach (PlusPropertyDescriptor groupedItem in data)
            {
                // groupedItem.GroupName = dropInfo.TargetGroup.Name.ToString();
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView)
            {
                ((ICollectionView)dropInfo.TargetCollection).Refresh();
            }
        }
Example #5
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            // I know this example is called DefaultsExample, but the default handlers don't know how
            // to set an item's group. You need to explicitly set the group on the dropped item like this.
            DragDrop.DefaultDropHandler.Drop(dropInfo);
            var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <GroupedItem>().ToList();

            foreach (var groupedItem in data)
            {
                groupedItem.Group = dropInfo.TargetGroup.Name.ToString();
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView)
            {
                ((ICollectionView)dropInfo.TargetCollection).Refresh();
            }
        }
Example #6
0
        public void Drop(IDropInfo dropInfo)
        {
            DragDrop.DefaultDropHandler.Drop(dropInfo);

            // Now extract the dragged group items and set the new group (target)
            var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <Card>().ToList();

            foreach (var groupedItem in data)
            {
                groupedItem.View.Content = dropInfo.Data;
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView view)
            {
                view.Refresh();
            }
        }
        /// <inheritdoc />
        public void Drop(IDropInfo dropInfo)
        {
            var textBox = (TextBox)dropInfo.VisualTarget;

            if (dropInfo.Data is IDataObject dataObject)
            {
                if (dataObject.GetDataPresent(DataFormats.Text))
                {
                    textBox.Text = dataObject.GetData(DataFormats.Text) as string ?? string.Empty;
                }
                else if (dataObject.GetDataPresent(DataFormats.FileDrop))
                {
                    // Note that you can have more than one file.
                    string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                    textBox.Text = string.Join(Environment.NewLine, files);
                }
            }
            else
            {
                var realData = DefaultDropHandler.ExtractData(dropInfo.Data);
                textBox.Text = string.Join(", ", realData.OfType <object>().ToArray());
            }
        }
Example #8
0
        void HandleEx(IDropInfo di)
        {
            DataGrid t = di.VisualTarget as DataGrid;

            var shooters = DefaultDropHandler.ExtractData(di.Data).OfType <Shooter>().ToList();

            if ((shooters != null) && (shooters.Count > 0))
            {
                foreach (Shooter s in shooters)
                {
                    MatchParticipation mp = new MatchParticipation()
                    {
                        ShooterID = s.ShooterID,
                        MatchID   = _m.MatchID,
                        Posse     = 0,
                        Category  = s.Category
                    };

                    if (t.Name.Equals("SpeedTicketGrid"))
                    {
                        mp.IsSpeedTicket = true;
                    }

                    _ctx.MatchParticipations.Attach(mp);

                    if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                    {
                        _ctx.MatchParticipations.Add(mp);
                    }

                    _ctx.SaveChanges();
                }
                Refresh();
                return;
            }
        }
        public static async Task Drop(IDropInfo dropInfo)
        {
            var invalid = new List <string>();

            var insertIndex     = dropInfo.UnfilteredInsertIndex;
            var destinationList = dropInfo.TargetCollection.TryGetList();

            if (dropInfo.DragInfo == null)
            {
                if (!(dropInfo.Data is DataObject data) || !data.ContainsFileDropList())
                {
                    return;
                }

                foreach (var o in data.GetFileDropList())
                {
                    try
                    {
                        var toInsert = await MainWindow.CreateGdItemAsync(o);

                        destinationList.Insert(insertIndex++, toInsert);
                    }
                    catch
                    {
                        invalid.Add(o);
                    }
                }
            }
            else
            {
                var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <object>().ToList();

                var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();
                if (sourceList != null)
                {
                    foreach (var o in data)
                    {
                        var index = sourceList.IndexOf(o);
                        if (index != -1)
                        {
                            sourceList.RemoveAt(index);
                            if (destinationList != null && Equals(sourceList, destinationList) && index < insertIndex)
                            {
                                --insertIndex;
                            }
                        }
                    }
                }

                if (destinationList != null)
                {
                    foreach (var o in data)
                    {
                        destinationList.Insert(insertIndex++, o);
                    }
                }
            }

            if (invalid.Any())
            {
                throw new InvalidDropException(string.Join(Environment.NewLine, invalid));
            }
        }
        public void Drop(IDropInfo dropInfo)
        {
            var dataAsList = DefaultDropHandler.ExtractData(dropInfo.Data);

            ((TextBox)dropInfo.VisualTarget).Text = string.Join(", ", dataAsList.OfType <object>().ToArray());
        }
Example #11
0
        public void Drop(IDropInfo dropInfo)
        {
            if (dropInfo == null || dropInfo.DragInfo == null)
            {
                return;
            }
            var insertIndex = dropInfo.InsertIndex != dropInfo.UnfilteredInsertIndex ? dropInfo.UnfilteredInsertIndex : dropInfo.InsertIndex;

            var itemsControl = dropInfo.VisualTarget as ItemsControl;

            if (itemsControl != null)
            {
                var editableItems = itemsControl.Items as IEditableCollectionView;
                if (editableItems != null)
                {
                    var newItemPlaceholderPosition = editableItems.NewItemPlaceholderPosition;
                    if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning && insertIndex == 0)
                    {
                        ++insertIndex;
                    }
                    else if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd && insertIndex == itemsControl.Items.Count)
                    {
                        --insertIndex;
                    }
                }
            }

            var destinationList = dropInfo.TargetCollection.TryGetList();
            var data            = DefaultDropHandler.ExtractData(dropInfo.Data);

            // default should always the move action/effect
            var copyData = (dropInfo.DragInfo.DragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
                           //&& (dropInfo.DragInfo.VisualSource != dropInfo.VisualTarget)
                           && !(dropInfo.DragInfo.SourceItem is HeaderedContentControl) &&
                           !(dropInfo.DragInfo.SourceItem is HeaderedItemsControl) &&
                           !(dropInfo.DragInfo.SourceItem is ListBoxItem);
            var selected = false;

            if (!copyData)
            {
                var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();

                foreach (var o in data)
                {
                    var index = sourceList.IndexOf(o);

                    var vm = (PlayListEntryViewModel)o;
                    selected = vm.IsSelected;

                    if (index != -1)
                    {
                        sourceList.RemoveAt(index);
                        // so, is the source list the destination list too ?
                        if (Equals(sourceList, destinationList) && index < insertIndex)
                        {
                            --insertIndex;
                        }
                    }
                }
            }
            foreach (var o in data)
            {
                var obj2Insert = (PlayListEntryViewModel)o;

                destinationList.Insert(insertIndex++, obj2Insert);

                if (selected)
                {
                    itemsControl.SetSelectedItem(obj2Insert);
                }
            }
        }