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

Crash when using items deriving from ContentControl #42

Closed
punker76 opened this issue Feb 18, 2013 · 4 comments
Closed

Crash when using items deriving from ContentControl #42

punker76 opened this issue Feb 18, 2013 · 4 comments

Comments

@punker76
Copy link
Owner

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

@ghost ghost assigned punker76 Feb 18, 2013
punker76 pushed a commit that referenced this issue Feb 18, 2013
@MrZoidberg
Copy link

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!

@punker76
Copy link
Owner Author

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

punker76 added a commit that referenced this issue Jul 19, 2013
now we can have items deriving from ContentControl
@punker76
Copy link
Owner Author

fixed with version 0.1.3.8

@sam0737
Copy link

sam0737 commented Sep 17, 2013

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.

punker76 added a commit that referenced this issue Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants