Reputation: 505
I have a ListBox in single-selection-mode containing some items. I implemented that the user is able to reorder the items by drag&drop. Everything works fine but it looks really ugly because the listbox automatically selects an item if the mousebutton is down and the cursor is moving over a item.
To be specific: To disable flickering in some situations I only move items when the item is dragged more than half over another item. When I start dragging item1 over item2 to place it behind item2, I want item1 to be selected while dragging. What happens is that item2 gets selected as soon as the cursor moves over item2. How can I get rid of this behavior?
I already tried to set e.Handled = true in PreviewMouseMove while dragging items, but this won't help.
If you like to see the code, it's here: http://pastebin.com/GTj96qV9. It is a behavior which enables any listbox which has a IList as DataSource to reorder its content by dragging.
Upvotes: 1
Views: 1286
Reputation: 505
The cleanest solution for me was to inherit from ItemsControl and implement my own "Selector".
Upvotes: 1
Reputation: 45106
This is a ListView. And I did not go into the detail of you code. But I do PreviewMouseLeftButtonDown on the ListViewItem and I don't have the problem you describe.
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListView1Item_PreviewMouseLeftButtonDown" />
<Setter Property="AllowDrop" Value="True" />
<EventSetter Event="DragDrop.Drop" Handler="ListView1Item_DragDrop" />
<Style.Triggers>
<DataTrigger Binding="{Binding DispDetail}" Value="False">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
Upvotes: 0
Reputation: 2380
This could screw over up the drop part, but did you try giving the ListBoxItem mouse capture? The MSDN has more details about this.
Hope this helps.
Upvotes: 0