WPF:有关 Scrollviewer MouseWheel 行为的帮助

发布于 2024-09-08 10:23:55 字数 523 浏览 4 评论 0原文

由于某种原因,当鼠标位于任何子项上时,我的滚动查看器不会处理鼠标滚轮事件(或至少在鼠标滚轮时滚动)。我希望这样当鼠标滚轮位于整个滚动查看器区域时,鼠标滚轮就会滚动。或者当您单击滚动条中包含的某些内容时,无论鼠标位于何处,它都会处理鼠标滚轮,因为它具有焦点。有什么简单的方法可以做到这一点吗?

XAML 中的基本布局树如下所示:

<ScrollViewer x:Name="scroller">
    <StackPanel x:Name="stackPanel" Orientation="Vertical">
        <Expander>
            <WrapPanel />
        </Expander>
        <Expander>
            <WrapPanel />
        </Expander>

    </StackPanel>
</ScrollViewer>

For some reason my scrollviewer does not process the mousewheel events (or at least scroll when you mouse wheel) when the mouse is over any child. I want it so that either when the mouse wheel is over the entire scrollviewer area, mousewheel scrolls. Either that or when you click on something contained in the scroller, it processes mouse wheel no matter where the mouse is because it has focus. Is there any easy way to do this?

The basic layout tree goes like so in XAML:

<ScrollViewer x:Name="scroller">
    <StackPanel x:Name="stackPanel" Orientation="Vertical">
        <Expander>
            <WrapPanel />
        </Expander>
        <Expander>
            <WrapPanel />
        </Expander>

    </StackPanel>
</ScrollViewer>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2024-09-15 10:23:55

我发现了问题所在。我实际上使用的是我创建的自定义 WrapPanel,但我忘记了该控件有自己的滚动查看器(因为它设置为“自动大小”所以不可见)。因此,包装面板的滚动器从外部滚动器窃取了鼠标滚轮事件。我取出了自定义包裹面板中的滚动条,现在一切正常。

I figured out the problem. I was actually using a custom WrapPanel that i created, and i forgot that control had its own scrollviewer (invisble since it was set to Auto size). So the wrappanel's scroller was stealing the mousewheel event from the outside scroller. I took out the scroller in the custom wrap panel and everything works normal now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文