How to set the horizontal scroll mouse wheel movement dependency?

1 Answer 1698 Views
ImageEditor
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
Psyduck asked on 19 Jul 2021, 06:14 AM

Hello.

I am using RadImageEditor.

I'm done with the setup. It actually works too.

But when I shift + wheel, not only horizontal movement but also vertical scrolling.

I want to move only horizontal scrolling when shift is pressed.

Which part should I control?


<telerik:RadImageEditor x:Name="xImageEditor" Image="{Binding RadImage}" behaviour:HorizontalScrollViewerHelper.IsShiftWheelProperty="True" IsPanningEnabled="True"/>
<imageEditor:ZoomController ImageEditor="{Binding ElementName=xImageEditor}" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>


public static class HorizontalScrollViewerHelper
    {
        public static bool GetIsShiftWheelProperty(DependencyObject obj) => (bool)obj.GetValue(IsShiftWheelProperty);
        public static void SetIsShiftWheelProperty(DependencyObject obj, bool value) => obj.SetValue(IsShiftWheelProperty, value);

        public static readonly DependencyProperty IsShiftWheelProperty
            = DependencyProperty.RegisterAttached("IsShiftWheel",
                typeof(bool),
                typeof(HorizontalScrollViewerHelper),
                new PropertyMetadata(false, HorizontalScrollCallback));

        private static void HorizontalScrollCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var imageEditor = d as RadImageEditor;
            imageEditor.PreviewMouseWheel += ImageEditor_PreviewMouseWheel;
        }

        private static void ImageEditor_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (((RadImageEditor)sender).ChildrenOfType<ScrollViewer>().FirstOrDefault() is ScrollViewer scrollViewer)
            {
                if(Keyboard.Modifiers.Equals(ModifierKeys.Shift))
                {
                    if (e.Delta < 0)
                    {
                        scrollViewer.LineRight();
                    }
                    else
                    {
                        scrollViewer.LineLeft();
                    }
                    //scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + (-e.Delta / 300));
                }
            }
        }
    }

 

Thanks.

 

Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
commented on 19 Jul 2021, 06:19 AM

Is there any shift wheel feature provided by Telerik? Visual studio xaml shift wheel function.

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 02 Aug 2021, 08:39 AM

Hello KIM,

Currently, the custom code in the HorizontalScrollViewerHelper class is using the LineRight() and LineLeft() methods of the ScrollViewer. This will move the horizontal scrollbar. If you want to update the only the vertical scrolling, you can use the LineUp() and LineDown() methods instead. For example:

private static void ImageEditor_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
	if (((RadImageEditor)sender).ChildrenOfType<ScrollViewer>().FirstOrDefault() is ScrollViewer scrollViewer)
	{
		if (Keyboard.Modifiers.Equals(ModifierKeys.Shift))
		{
			if (e.Delta < 0)
			{
				scrollViewer.LineUp();
			}
			else
			{
				scrollViewer.LineDown();
			}
		}
	}
}

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ImageEditor
Asked by
Psyduck
Top achievements
Rank 5
Bronze
Bronze
Bronze
Answers by
Martin Ivanov
Telerik team
Share this question
or