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

  • 相关阅读:
    Neko Performs Cat Furrier Transform CodeForces
    Neko does Maths CodeForces
    Game HDU
    HDU
    CF1155D Beautiful Array 贪心,dp
    二维差分
    B
    一维差分
    状压dpHDU
    [转载] HBase vs Cassandra:我们迁移系统的原因
  • 原文地址:https://www.cnblogs.com/grj1046/p/5062887.html
Copyright © 2011-2022 走看看