<i id='7zPcP'><tr id='7zPcP'><dt id='7zPcP'><q id='7zPcP'><span id='7zPcP'><b id='7zPcP'><form id='7zPcP'><ins id='7zPcP'></ins><ul id='7zPcP'></ul><sub id='7zPcP'></sub></form><legend id='7zPcP'></legend><bdo id='7zPcP'><pre id='7zPcP'><center id='7zPcP'></center></pre></bdo></b><th id='7zPcP'></th></span></q></dt></tr></i><div id='7zPcP'><tfoot id='7zPcP'></tfoot><dl id='7zPcP'><fieldset id='7zPcP'></fieldset></dl></div>
      <bdo id='7zPcP'></bdo><ul id='7zPcP'></ul>

        <legend id='7zPcP'><style id='7zPcP'><dir id='7zPcP'><q id='7zPcP'></q></dir></style></legend>

        <small id='7zPcP'></small><noframes id='7zPcP'>

        <tfoot id='7zPcP'></tfoot>

        在 wpf 中禁用项目控件上的鼠标滚轮

        时间:2023-10-07

                <tfoot id='raHNr'></tfoot>
              • <small id='raHNr'></small><noframes id='raHNr'>

                <i id='raHNr'><tr id='raHNr'><dt id='raHNr'><q id='raHNr'><span id='raHNr'><b id='raHNr'><form id='raHNr'><ins id='raHNr'></ins><ul id='raHNr'></ul><sub id='raHNr'></sub></form><legend id='raHNr'></legend><bdo id='raHNr'><pre id='raHNr'><center id='raHNr'></center></pre></bdo></b><th id='raHNr'></th></span></q></dt></tr></i><div id='raHNr'><tfoot id='raHNr'></tfoot><dl id='raHNr'><fieldset id='raHNr'></fieldset></dl></div>
                  <bdo id='raHNr'></bdo><ul id='raHNr'></ul>

                  <legend id='raHNr'><style id='raHNr'><dir id='raHNr'><q id='raHNr'></q></dir></style></legend>
                    <tbody id='raHNr'></tbody>
                  本文介绍了在 wpf 中禁用项目控件上的鼠标滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个用户控件,它有一个滚动查看器,然后是一堆子控件,如文本框、单选按钮和列表框等.我可以使用鼠标滚轮滚动父滚动查看器,直到我的鼠标落在列表框内,然后鼠标滚轮事件开始进入列表框.

                  I have a usercontrol that has a scrollviewer, then a bunch of child controls like text boxes, radio buttons, and listboxes, etc inside of it. I can use the mouse wheel to scroll the parent scrollviewer until my mouse lands inside a listbox then, the mouse wheel events start going to the listbox.

                  有没有办法让列表框将这些事件发送回父控件?像这个问题建议的那样从父控件内部删除列表框(在 ScrollViewer 的子控件上方时鼠标滚轮不起作用) 不是解决方案.

                  Is there any way to have the listbox send those events back up to the parent control? Removing the listbox from within side the parent control like this question suggests (Mouse wheel not working when over ScrollViewer's child controls) isnt a solution.

                  我试过了

                  private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
                  {
                      e.Handled = true;
                  }
                  

                  但这也没用.

                  谢谢

                  推荐答案

                  您引用的答案正是导致您的问题的原因,您的 ScrollViewer 中的 ListBox(由 ScrollViewer 等组成)捕获了 MouseWheel 事件并处理它,防止它冒泡,因此 ScrollViewer 不知道该事件曾经发生过.

                  The answer you have referenced is exactly what is causing your problem, the ListBox (which is composed of among other things a ScrollViewer) inside your ScrollViewer catches the MouseWheel event and handles it, preventing it from bubbling and thus the ScrollViewer has no idea the event ever occurred.

                  为您的 ListBox 使用以下极其简单的 ControlTemplate 进行演示(注意它没有 ScrollViewer,因此不会捕获 MouseWheel 事件) ScrollViewer 仍然会随着鼠标在 ListBox 上滚动.

                  Use the following extremely simple ControlTemplate for your ListBox to demonstrate (note it does not have a ScrollViewer in it and so the MouseWheel event will not be caught) The ScrollViewer will still scroll with the mouse over the ListBox.

                  <UserControl.Resources>
                       <ControlTemplate x:Key="NoScroll">
                           <ItemsPresenter></ItemsPresenter>
                       </ControlTemplate>
                  </UserControl.Resources>
                  
                  <ScrollViewer>
                      <SomeContainerControl>
                          <.... what ever other controls are inside your ScrollViewer>
                          <ListBox Template="{StaticResource NoScroll}"></ListBox>
                      <SomeContainerControl>
                  </ScrollViewer>
                  

                  您确实可以选择在鼠标进入 ScrollViewer 时捕获鼠标,因此它会继续接收所有鼠标事件,直到鼠标被释放,但是此选项将要求您将任何进一步的鼠标事件委托给包含在 ScrollViewer 中的控件ScrollViewer 如果您需要响应...以下 MouseEnter MouseLeave 事件处理程序就足够了.

                  You do have the option of capturing the mouse when it enters the ScrollViewer though so it continues to receive all mouse events until the mouse is released, however this option would require you to delgate any further mouse events to the controls contained within the ScrollViewer if you want a response...the following MouseEnter MouseLeave event handlers will be sufficient.

                  private void ScrollViewerMouseEnter(object sender, MouseEventArgs e)
                  {
                      ((ScrollViewer)sender).CaptureMouse();
                  }
                  
                  private void ScrollViewerMouseLeave(object sender, MouseEventArgs e)
                  {
                      ((ScrollViewer)sender).ReleaseMouseCapture();
                  }
                  

                  然而,我提供的解决方法都不是真正的首选,我建议重新考虑您实际尝试做的事情.如果您在问题中解释您要达到的目标,我相信您会得到更多建议...

                  Neither of the workarounds I have provided are really preferred however and I would suggest rethinking what you are actually trying to do. If you explain what you are trying to achieve in your question I'm sure you will get some more suggestions...

                  这篇关于在 wpf 中禁用项目控件上的鼠标滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:当我的 ListBox 中有图像时,为什么会出现 OutOfMemoryException? 下一篇:将列表框绑定到列表&lt;对象&gt;在 WinForms 中

                  相关文章

                  <legend id='sRS1X'><style id='sRS1X'><dir id='sRS1X'><q id='sRS1X'></q></dir></style></legend>

                  <i id='sRS1X'><tr id='sRS1X'><dt id='sRS1X'><q id='sRS1X'><span id='sRS1X'><b id='sRS1X'><form id='sRS1X'><ins id='sRS1X'></ins><ul id='sRS1X'></ul><sub id='sRS1X'></sub></form><legend id='sRS1X'></legend><bdo id='sRS1X'><pre id='sRS1X'><center id='sRS1X'></center></pre></bdo></b><th id='sRS1X'></th></span></q></dt></tr></i><div id='sRS1X'><tfoot id='sRS1X'></tfoot><dl id='sRS1X'><fieldset id='sRS1X'></fieldset></dl></div>
                  1. <tfoot id='sRS1X'></tfoot>

                      • <bdo id='sRS1X'></bdo><ul id='sRS1X'></ul>

                      <small id='sRS1X'></small><noframes id='sRS1X'>