When DropTarget is not an ItemsControl

90 views
Skip to first unread message

0x6e6562

unread,
Jun 30, 2010, 12:17:09 PM6/30/10
to gong-wpf-dragdrop
Hi,

Maybe I'm missing something here but it would seem that while you can
set the DropTarget flag on a UIElement, only an ItemsControl will have
the dropInfo.Target property set.

I'm trying to use a TextBlock as a target and in the Drop(DropInfo
info) callback, the Target property in the DropInfo is null.

So as a workaround I'm introspecting the parent of VisualTarget
property to get access to the target item.

Is this an actual restriction or am I using this wrongly?

Cheers,

Ben

gro...@googlemail.com

unread,
Jun 30, 2010, 2:19:51 PM6/30/10
to gong-wpf-dragdrop
Hi Ben,

Not entirely sure I understand the problem. The DropTarget class
exposes the following properties related to the drop destination:

- TargetCollection - the collection that the target ItemsControl is
bound to.
- TargetItem - the item in TargetCollection that is being dropped
onto.
- VisualTarget - the actual UI control being dropped onto.

In the case of dropping onto a non-ItemsControl then the first 2
properties obviously cannot apply, so you just get a reference to the
UIElement, which in your case should be your TextBlock. Am I
misunderstanding something here?

Steven

Ben Hood

unread,
Jul 1, 2010, 6:02:21 AM7/1/10
to gong-wpf...@googlegroups.com
Steven,

On Wed, Jun 30, 2010 at 7:19 PM, gro...@googlemail.com
<gro...@googlemail.com> wrote:
> In the case of dropping onto a non-ItemsControl then the first 2
> properties obviously cannot apply, so you just get a reference to the
> UIElement, which in your case should be your TextBlock. Am I
> misunderstanding something here?

I think you have understood the question - I am trying to drop onto a
TextBlock element, which does not inherit from ItemsControl, so as you
describe, the VisualTarget property returns a reference to the
TextBlock.

I guess I kind of answered my question by asking it in the first place.

My confusion probably arose from the fact that I was dropping objects
into particular cells within a grouped datagrid. I wanted to narrow
down the target area so that only you can only drop into cells that
make sense to drop things into, as opposed to just dropping the object
anywhere on the grid. Obviously, if I go down this route, I'll have to
introspect the visual targets manually.

Sorry about the confusion and thanks for your help,

Ben

Reply all
Reply to author
Forward
0 new messages