punker76/gong-wpf-dragdrop

Crash when using items deriving from ContentControl

punker76 opened this issue · 4 comments

Original author: natxm...@gmail.com (December 15, 2011 10:10:19)

What steps will reproduce the problem?

  1. Use a control that derives from ContentControl (Label, Button) for the ItemTemplate in the ItemsControl, like in this example:
<ItemsControl ItemsSource="{Binding Collection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
                <Label>WhatEver</Label>  
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

What is the expected output? What do you see instead?

  • When you try to drag any item, an exception is thrown.

What version of the product are you using? On what operating system?

  • 1.3, XP

Please provide any additional information below.

It all happens in DragInfo's constructor.
This line fails to retrieve the correct container:
UIElement item = itemsControl.GetItemContainer((UIElement)e.OriginalSource);

Therefore itemParent is null:
ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item);

Original issue: http://code.google.com/p/gong-wpf-dragdrop/issues/detail?id=42

Hi, are you going to address this issue? I have a dirty fix with a special property for root ItemsControl that defines a UID of the items container that should be taken for the drag&drop operations (in GetVisualAncestor method). Are you interested in a pull request with this fix?

Thanks!

@MrZoidberg hi, feel free to push a pr. i hope your fix is not too dirty... ;-)

fixed with version 0.1.3.8

The change break my case.

<ItemsControl.Template>
  <ControlTemplate>
    <ScrollViewer VerticalScrollBarVisibility="Auto" Padding="{TemplateBinding Padding}">
      <ItemsPresenter />
    </ScrollViewer>
  </ControlTemplate>
</ItemsControl.Template>

in public static DependencyObject GetVisualAncestor(this DependencyObject d, Type type, ItemsControl itemsControl)
It is looking for the highest ContentPresenter under itemsControl before returning - which ScrollContentPresent is a kind of ContentPresenter.

Changing to

        if (item is ItemsPresenter || item == itemsControl) {
          return lastFoundItemByType;
        }

terminate at ItemsPresenter fix my problem.