2016-07-15 21 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