开发者

Automatic ListBox Selection/SelectedItem/SelectedIndex changed while moving mouse out of ListBox

开发者 https://www.devze.com 2023-02-26 00:32 出处:网络
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 mous开发

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 mous开发者_开发技巧e 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.

Automatic ListBox Selection/SelectedItem/SelectedIndex changed while moving mouse out of ListBox

<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>`


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);


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

0

精彩评论

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