开发者

Cant Drag ListBoxItem Adorner outside of ListBox in WPF -ScrollViewerProblem

I am working with a WPF application that uses alot of drag and drop. Everything is working fine, with exception of ListBoxItems. I have a ListBox with List开发者_Python百科BoxItems that can be dragged to another target( a StackPanel). The problem is, when I drag the cursor outside the ListBox, I cant see the Adorner that I have setup with the ListBoxItem?

I know this is a common problem, but I am just not sure how to fix it. Is there something that I need to do to allow me to drag outside of the ListBox control?

Below I have attached what the UI looks like so far. As you can see, there is a ListBox on the bottom left. When I drag an item, the adorner appears, and follows the cursor around while the cursor is over the ListBox, but if I try to move the cursor away from the listbox, the Adorner seems to almost go under the other controls(zIndex?).

Cant Drag ListBoxItem Adorner outside of ListBox in WPF -ScrollViewerProblem

Edit - Solution I have changed the code to handle the AdornerLayer relative to the window as oppose to relative to the AdornedElement

So I changed

    layer = AdornerLayer.GetAdornerLayer(_originalElement);

to

    layer = AdornerLayer.GetAdornerLayer(this);

This solved the problem of the ScrollViwer clipping the AdornerLayer


The ListBox (or, to be specific, the ScrollViewer within the listbox) clips any adorners attached to it's children. This is done to ensure that adorners for items scrolled out of view are not shown. To get around this, you need to explicitly put thing in the Window's adorner and not that of the listbox or listboxitem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜