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

  • 相关阅读:
    100篇论文
    Tengine vs openresty
    Dottrace跟踪代码执行时间
    Linux Server
    Linux+Apache+Mysql+Php
    linux+nginx+mysql+php
    tshark命令行的使用(转)
    tcpdump VS tshark用法(转)
    Lua语言在Wireshark中使用(转)
    doc-remote-debugging.html
  • 原文地址:https://www.cnblogs.com/grj1046/p/5062887.html
Copyright © 2011-2022 走看看