views:

498

answers:

2

I want to drop something not on the whole ListBox, but on a specific ListBoxItem. I'm handling the ListBox' Drop event - how can I find out, on which item the mouse is pointing?

A: 

You can use VisualTreeHelper.HitTest to figure out which ListViewItem is at the given point. That said, there may well be an easier way to do what you require, but there's not really enough info to go on.

HTH, Kent

Kent Boogaart
I tried this code:if (e.Data.GetDataPresent(typeof(Songs))) { var result = VisualTreeHelper.HitTest(this.Playlists, Mouse.GetPosition(this.Playlists)); (in the Drop-handler) but it always returns null!
eWolf
A: 
if (e.Data.GetDataPresent(typeof(Songs))) 
 { 
   var result = VisualTreeHelper.HitTest(myCanvas, Mouse.GetPosition(this.Playlists));
 }

If using a canvas, try performing your hittest relative to the Canvas (replace "myCanvas" with the reference)

Gurdas Nijor
this.Playlists is the ListBox, shouldn't this work?
eWolf
is the playlist contained in a Canvas?
Gurdas Nijor