0

Have a ListBox with couple of items. Select any item (say the v.first item) and keep try to Drag it in empty area (Outside of listbox), ListBox selection is getting changed. Albeit I'm moving mouse in area out of ListBox.

I want selection change only when i move mouse within the ListBox. Or completely disable the selection change while mouse move (Dragged). Here is the snapshot of a small poc.

enter image description here

<Grid>  
    <ListBox HorizontalAlignment="Left" Margin="111,49,0,180" Name="listBox1" Width="154">  
        <ListBoxItem BorderThickness="2" Height="50" Width="Auto" Name="heig" BorderBrush="Chocolate">Rohit Item 1</ListBoxItem>  
        <ListBoxItem Height="50" BorderThickness="2" BorderBrush="Blue"  >Vivek</ListBoxItem>  
        <ListBoxItem Height="50" BorderBrush="Cyan" BorderThickness="2"  >Gaurav</ListBoxItem>  
        <ListBoxItem Name="height" Height="50" BorderBrush="CornflowerBlue" BorderThickness="2" >Asit Item 2</ListBoxItem>  
    </ListBox>  
</Grid>`
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Rohit
  • 6,365
  • 14
  • 59
  • 90

2 Answers2

0

I just stumbled over this topic again and I have to tell you that there is no perfect solution but a, imho, good workaround. You can find it here

Community
  • 1
  • 1
seveves
  • 1,282
  • 4
  • 17
  • 37
0

You should capture the mouse while dragging, preventing other input from happening while you are dragging. This is done when drag starts:

Mouse.Capture(listBox);
Bas
  • 26,772
  • 8
  • 53
  • 86
  • Tried but not working. Still selection getting changed. I tried mouse capture in DragEnter, DragOver events of listbox – Rohit Apr 15 '11 at 10:31
  • The problem there is the selection can change between mousedown and dragstart (i.e. during the drag-detecction distance). This becomes a problem when you cross an ListBoxItem's boundary during that distance as you've clicked on one item, but a different item is selected when the drag actually occurs. – Mark A. Donohoe Nov 29 '12 at 18:11