2016-07-15 39 views
0

我正在創建一個與視覺工作室撤消按鈕相同的撤消按鈕。我希望用戶能夠將鼠標懸停在項目上方,並選擇其上方的每個項目。點擊上面的所有項目都會被傳入並執行操作。如果用戶自己單擊按鈕,則撤消頂部對象。問題:沒有使用上下文菜單,也不知道我在用wpf做什麼。現在用戶可以將鼠標懸停在上面,但只有鼠標在上面的對象被選中(所有後面的代碼都是vb.net)。所有幫助表示讚賞!菜單中的MutliSelect列表框

代碼:

<MenuItem Header="Undo" Name="MenuUndo" IsEnabled="True"> 
    <MenuItem.Icon> 
     <Image Source="Undo.png" Width="24" Height="24" /> 
    </MenuItem.Icon> 
    <StackPanel> 
     <ListBox Name="ListBoxUndo" HorizontalAlignment="Stretch " 
       VerticalAlignment="Stretch" Width="177" Height="100 " Margin="-33,-5,-65,-5" 
       ScrollViewer.VerticalScrollBarVisibility="Visible" IsEnabled="True" 
       SelectionMode ="Multiple"> 

      <ListBox.ItemContainerStyle> 
       <Style TargetType="ListBoxItem"> 
        <Style.Triggers> 
         <Trigger Property="IsMouseOver" Value="True"> 
          <Setter Property="IsSelected" Value="True"/> 
         </Trigger> 
        </Style.Triggers> 
       </Style> 
      </ListBox.ItemContainerStyle> 

     </ListBox>      
    </StackPanel> 

</MenuItem> 

這裏是它目前的樣子: enter image description here

回答

0

嗯,我得到了它使用滾輪其作品的一種較好的反正工作!這裏是我添加的代碼:

Private Sub ListBoxUndo_PreviewMouseWheel(sender As Object, e As MouseWheelEventArgs) Handles ListBoxUndo.PreviewMouseWheel 
    ListBoxUndo.Focus() 
    Try 
     If e.Delta < 1 Then 
      'highlight next item 
      ListBoxUndo.SelectedItems.Add(ListBoxUndo.Items(ListBoxUndo.SelectedItems.Count)) 

     Else 
      'remove last selected item 
      ListBoxUndo.SelectedItems.Remove(ListBoxUndo.Items(ListBoxUndo.SelectedItems.Count - 1)) 
     End If 
    Catch ex As Exception 

    End Try 

End Sub