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

  • 相关阅读:
    五种线程池的分类与作用
    什么是死锁?
    事务隔离级别区分,未提交读,提交读,可重复读
    共享锁(读锁)和排他锁(写锁)
    java中的成员变量和全局变量的区别
    Algorithm
    6
    5
    4
    3
  • 原文地址:https://www.cnblogs.com/grj1046/p/5062887.html
Copyright © 2011-2022 走看看