zoukankan      html  css  js  c++  java
  • Wpf ScrollViewer with WrapPanel 使用鼠标滚轮水平滚动内容

    为WrapPanel添加水平滚动条,当禁用垂直滚动条后使用鼠标无法滚动,竟然还需要自己写代码来实现,真真是挺无语呢,不知道算不算是一个bug。

     <Grid Background="Transparent">
      <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto" 
             PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
       <Rectangle Width="2000" Height="1000" Fill="Red"/>
      </ScrollViewer>
     </Grid>
    
      private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
      {
       ScrollViewer scrollviewer= sender as ScrollViewer;
       if (e.Delta > 0)
        scrollviewer.LineLeft();
       else
        scrollviewer.LineRight();
       e.Handled = true;
      }
    

    可以实现效果,感觉滚动不是很灵活,自作聪明的调用了两次LineLeft(),搞定。

            private void scrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
            {
                ScrollViewer sv = sender as ScrollViewer;
                //move twice make it flexible
                if (e.Delta>0)
                {
                    sv.LineLeft();
                    sv.LineLeft();
                }
                else
                {
                    sv.LineRight();
                    sv.LineRight();
                }
                e.Handled = true;
            }
    

    原文链接 how to enable horizontal scrolling with mouse wheel?

    附赠一个WinRT版的解决方案

    ScrollViewer Horizontal mouse wheel scrolling

    From what I've done so far you should just be able to set the ScollViewer's style to

    Style="{StaticResource HorizontalScrollViewerStyle}"
    

    Which is defined in StandardStyles.xaml

  • 相关阅读:
    codeforces 501 C,D,E
    bzoj 3172 单词 ac自动机|后缀数组
    HDU2459 后缀数组+RMQ
    POJ 3294 二分找超过一半字符串中存在的子串
    头文件
    python爬取文本
    python爬取图片
    NEW
    dsu on tree 练习题
    lzz分块+莫队
  • 原文地址:https://www.cnblogs.com/grj1046/p/5062887.html
Copyright © 2011-2022 走看看