2011-04-15 26 views
0

ListBox與幾個項目。選擇任何項目(比如v.first項目),並保持嘗試拖動它在空白區域(列表框外),ListBox選擇正在改變。雖然我在ListBox以外的區域移動鼠標。當將鼠標移出列表框時,自動列表框選擇/ SelectedItem/SelectedIndex發生變化

我只希望在ListBox內移動鼠標時選擇更改。或者在鼠標移動(拖拽)時完全禁用選擇更改。這是一個小型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>` 
+0

你可以發佈一些xaml代碼? – 2011-04-15 11:02:19

回答

0

你應該捕獲鼠標拖動,防止當你拖動發生其他輸入。這是當拖動開始做:

Mouse.Capture(listBox); 
+0

試過但沒有工作。仍然選擇得到改變。我嘗試使用DragEnter中的鼠標捕獲,列表框DragOver事件 – Rohit 2011-04-15 10:31:16

+0

問題是選擇可以在mousedown和dragstart之間變化(即在拖動檢測距離期間)。當您單擊某個項目時,如果在該距離內穿過ListBoxItem的邊界,這會成爲問題,但實際發生拖動時將選擇不同的項目。 – MarqueIV 2012-11-29 18:11:20

0

我只是絆了這個話題再次,我要告訴你,沒有完美的解決方案,但一個,恕我直言,良好的解決方法。你可以找到它here

相關問題