none
对于控件中的滚动条,鼠标滚轮不能实现滚动,是否有解决方法? RRS feed

答案

全部回复

  • 用JavaScript参考DeepZoom有个Wheel类,就是JavaScript加的滚轮
    如果您觉得对您有帮助,请在“是否有帮助”点“是”;如果你觉得回复很满意,请“标记为已解答”
    2009年7月13日 14:50
    版主
  • SL3 一个新的feature就是对MouseWheel event的支持,可以自己在event 处理中通过AutomationPeer实现"自动"滚动的动作.

    2009年7月13日 15:26
  • sl3太强大了,终于有滚轮了,我还没来及读完sdk document :)
    如果您觉得对您有帮助,请在“是否有帮助”点“是”;如果你觉得回复很满意,请“标记为已解答”
    2009年7月13日 19:42
    版主
  •     public class ScrollViewerExtensions : DependencyObject
        {
            public static readonly DependencyProperty EnableMouseWheelProperty = DependencyProperty.RegisterAttached("EnableMouseWheel", typeof(bool), typeof(ScrollViewerExtensions), new PropertyMetadata(false, OnEnableMouseWheelPropertyChanged));
            
            public static void SetEnableMouseWheel(DependencyObject obj, bool value)
            {
                obj.SetValue(EnableMouseWheelProperty, value);
            }
    
            public static bool GetEnableMouseWheel(DependencyObject obj)
            {
                return (bool)obj.GetValue(EnableMouseWheelProperty);
            }
    
            public static void OnEnableMouseWheelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                ScrollViewer scrollViewer = d as ScrollViewer;
                if ((bool)e.NewValue)
                {
                    scrollViewer.MouseWheel += new MouseWheelEventHandler(scrollViewer_MouseWheel);
                }
            }
    
            public static void scrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
            {
                ScrollViewer viewer = sender as ScrollViewer;
                if (viewer == null)
                    return;
                double num = Math.Abs((int)(e.Delta / 4));
                double offset = 0.0;
                if (e.Delta > 0)
                {
                    offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));
                }
                else
                {
                    offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num);
                }
                if (offset != viewer.VerticalOffset)
                {
                    viewer.ScrollToVerticalOffset(offset);
                    e.Handled = true;
                }
            }
        }
    

    我写了一个ScrollViewerExtensions的类,你可以直接用

    在Xaml里或cs里都可以

    2009年7月14日 1:41
  • 你好,我是天使坠,前些日子我有一个好朋友,她交给了我一个方法,贴出来给你试试,希望能帮助你!

    <script type="text/javascript">
        var _control;
        function onLoad(sender) {
            _control = sender.get_element();
            if (window.addEventListener)
                window.addEventListener('DOMMouseScroll', OnMouseWheelTurned, false);
            window.onmousewheel = document.onmousewheel = OnMouseWheelTurned;
        }
        function OnMouseWheelTurned(event) { 
         var delta = 0;
        if (!event)
            event = window.event;
        if (event.wheelDelta)
        {
            delta = event.wheelDelta;
            if (window.opera)
                delta = -delta;
        }
        else if (event.detail)
            delta = -event.detail;
        if (delta)
        {
            if (delta > 0)
                _control.content.magic.zoomin();
            else
                _control.content.magic.zoomout();
    }
        if (event.preventDefault)
            event.preventDefault();
        event.returnValue = false;
    }
    
    </script>
    <Grid x:Name="LayoutRoot" Background="White">
            <Canvas>
                <!--<Canvas.RenderTransform>
                   <ScaleTransform x:Name="ZoomTransform" CenterX="0.5" CenterY="0.5" />
                </Canvas.RenderTransform>-->
                <Rectangle x:Name="rect" Width="100" Height="100" Fill="AliceBlue">
                    <Rectangle.RenderTransform>
                        <ScaleTransform x:Name="ZoomTransform" CenterX="50" CenterY="50"  />
                    </Rectangle.RenderTransform>
                </Rectangle>
                <!--<Image Source="a.jpg" x:Name="img"></Image>-->
            </Canvas>
    </Grid>



    namespace test
    {
        [ScriptableType]
        public partial class Page : UserControl
        {
            public Page()
            {
                InitializeComponent();
            }
    
            [ScriptableMember()]
            public void zoomin()
            {
                ZoomTransform.ScaleX += 0.1;
                ZoomTransform.ScaleY += 0.1;
    
            }
    
            [ScriptableMember()]
            public void zoomout()
            {
                ZoomTransform.ScaleX -= 0.1;
                ZoomTransform.ScaleY -= 0.1;
    



    }


    努力!写一个js解析器,一个svg插件,一个绘图程序,做好自己,呵呵~!
    2009年7月15日 11:11
    版主
  •     public class ScrollViewerExtensions : DependencyObject
    
        {
    
            public static readonly DependencyProperty EnableMouseWheelProperty = DependencyProperty.RegisterAttached("EnableMouseWheel", typeof(bool), typeof(ScrollViewerExtensions), new PropertyMetadata(false, OnEnableMouseWheelPropertyChanged));
    
            
    
            public static void SetEnableMouseWheel(DependencyObject obj, bool value)
    
            {
    
                obj.SetValue(EnableMouseWheelProperty, value);
    
            }
    
    
    
            public static bool GetEnableMouseWheel(DependencyObject obj)
    
            {
    
                return (bool)obj.GetValue(EnableMouseWheelProperty);
    
            }
    
    
    
            public static void OnEnableMouseWheelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    
            {
    
                ScrollViewer scrollViewer = d as ScrollViewer;
    
                if ((bool)e.NewValue)
    
                {
    
                    scrollViewer.MouseWheel += new MouseWheelEventHandler(scrollViewer_MouseWheel);
    
                }
    
            }
    
    
    
            public static void scrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
    
            {
    
                ScrollViewer viewer = sender as ScrollViewer;
    
                if (viewer == null)
    
                    return;
    
                double num = Math.Abs((int)(e.Delta / 4));
    
                double offset = 0.0;
    
                if (e.Delta > 0)
    
                {
    
                    offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));
    
                }
    
                else
    
                {
    
                    offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num);
    
                }
    
                if (offset != viewer.VerticalOffset)
    
                {
    
                    viewer.ScrollToVerticalOffset(offset);
    
                    e.Handled = true;
    
                }
    
            }
    
        }
    
    
    
    

    我写了一个ScrollViewerExtensions的类,你可以直接用

    在Xaml里或cs里都可以


    这个怎么用?
    aaaa
    2009年7月17日 3:59
  • 这是用Javascript实现的,用DomBridge来连接,
    在SL3里,可以直接用MouseWheel event + AutomationPeer来实现。
    举个DataGrid的例子:

    dataGrid.MouseWheel += new MouseWheelEventHandler(dataGrid_MouseWheel);

    void dataGrid_MouseWheel(object sender, MouseWheelEventArgs e)

            {

                DataGrid dg = sender as DataGrid

                DataGridAutomationPeer dapeer = (DataGridAutomationPeer)DataGridAutomationPeer.CreatePeerForElement(dg);

                IScrollProvider provider = (IScrollProvider)dapeer.GetPattern(PatternInterface.Scroll);

                if (provider != null)

                {

                    if (e.Delta < 0)

                        provider.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement);

                    if (e.Delta > 0)

                        provider.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallDecrement);

                }

     

            }

     

    2009年7月17日 5:04
  • 我看到SL3的System.Windows.Controls命名空间下多了一个ScrollViewerExtensions,但是是静态类,我没能成功在xaml里设置IsMouseWheelScrollingEnabled,但是后台是可以的

    不知道是不是正常的

    2009年7月20日 10:18
  • 如果是SL3的话!是不用写任何代码的~

    System.Windows.Controls下,MS已经提供了ScrollViewerExtensiens,有兴趣的可以看看


    我这个没那个功能丰富,保存为一个class,然后ScrollViewerExtensiens.SetEnableMouseWheel(scrollViewer, true);就可以了

    2009年7月20日 12:15