Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DropInfo.InsertPosition Evaluation Issue #150

Closed
pschimmel opened this issue Nov 25, 2015 · 6 comments
Closed

DropInfo.InsertPosition Evaluation Issue #150

pschimmel opened this issue Nov 25, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@pschimmel
Copy link

Hello!

I'm not sure if this is a bug of your library.
I have a TreeView with several hierarchical items. If I drop a item after the last item on the same level it should insert the item at the end of the list of subitems on this level.
However somehow the DropInfo.InsertPosition is evaluated wrong.
As you can see on the following screenshot the value of dropInfo.InsertPosition is AfterTargetItem as it should be. However it is still evaluated as BeforeTargetItem and the first line after the if is executed.

vs

I also tried Enum.HasFlag with the same result.
Is there something I'm missing?

@punker76
Copy link
Owner

@pschimmel With which version does this happen?

@pschimmel
Copy link
Author

I'm using version 0.1.4.3 (.NET 4)

@punker76
Copy link
Owner

@pschimmel so can you test the latest source? also avaialble via pre nuget. thx!

@pschimmel
Copy link
Author

pschimmel commented Nov 25, 2015

I updated to version 1.0.0 Alpha 011 but still no luck.
I was able to reproduce the issue in your DefaultsExample, however it seems that I cannot upload a zip file as an attachment to a post.

The changes I made are rather simple, maybe you could reproduce them in your environment (sorry for the sloppy programming style):

I changed the XAML of the MainWindow under the "Bound TreeViews" tab as follows:

 <TreeView Grid.Column="0"
                  Grid.Row="1"
                  ItemsSource="{Binding TreeCollection}"
                  dd:DragDrop.IsDragSource="True"
                  dd:DragDrop.IsDropTarget="True"
                  dd:DragDrop.DropHandler="{Binding}"
                  dd:DragDrop.UseDefaultDragAdorner="True">

Then I changed the Data class:

    void IDropTarget.DragOver(IDropInfo dropInfo)
    {
      DragDrop.DefaultDropHandler.DragOver(dropInfo);
      if ((dropInfo.Data is CustomDataModel) || dropInfo.TargetGroup == null) {
        //dropInfo.Effects = System.Windows.DragDropEffects.None;
      }
    }

    void IDropTarget.Drop(IDropInfo dropInfo)
    {
      DragDrop.DefaultDropHandler.Drop(dropInfo);
      if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem))
        MessageBox.Show("B-4"); // This is shown if example fails
      var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType<GroupedItem>().ToList();
      foreach (var groupedItem in data) {
        groupedItem.Group = dropInfo.TargetGroup.Name.ToString();
      }
      if (dropInfo.TargetCollection is ICollectionView) {
        ((ICollectionView)dropInfo.TargetCollection).Refresh();
      }
    }

If you drag Item 0 and drop it after Item 9 a MessageBox is shown although it should not have been.

@kosorin
Copy link

kosorin commented Jan 14, 2016

Thats because RelativeInsertPosition should be changed. Check issue #60

You can test it:

        private void Test(RelativeInsertPosition value, RelativeInsertPosition has, bool expected)
        {
            System.Diagnostics.Debug.WriteLine("Value = {0}; Expected = {1}", value.HasFlag(has), expected);
        }

        private void TestRelativeInsertPosition()
        {
            Test(RelativeInsertPosition.BeforeTargetItem, RelativeInsertPosition.BeforeTargetItem, true);
            Test(RelativeInsertPosition.AfterTargetItem, RelativeInsertPosition.BeforeTargetItem, false);
            Test(RelativeInsertPosition.TargetItemCenter, RelativeInsertPosition.BeforeTargetItem, false);

            Test(RelativeInsertPosition.BeforeTargetItem | RelativeInsertPosition.AfterTargetItem, RelativeInsertPosition.BeforeTargetItem, true);
            Test(RelativeInsertPosition.BeforeTargetItem | RelativeInsertPosition.TargetItemCenter, RelativeInsertPosition.BeforeTargetItem, true);
            Test(RelativeInsertPosition.AfterTargetItem | RelativeInsertPosition.TargetItemCenter, RelativeInsertPosition.BeforeTargetItem, false);

            Test(RelativeInsertPosition.BeforeTargetItem | RelativeInsertPosition.AfterTargetItem | RelativeInsertPosition.TargetItemCenter, RelativeInsertPosition.BeforeTargetItem, true);
        }

And output:

Value = True; Expected = True
Value = True; Expected = False
Value = True; Expected = False
Value = True; Expected = True
Value = True; Expected = True
Value = True; Expected = False
Value = True; Expected = True

@punker76 punker76 added the Bug label Feb 3, 2016
@punker76 punker76 added this to the v1.0.0 milestone Feb 3, 2016
@punker76 punker76 self-assigned this Feb 3, 2016
@punker76
Copy link
Owner

punker76 commented Aug 1, 2016

@pschimmel @kosorin Should be fixed with 3b0995c

@punker76 punker76 closed this as completed Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants