0

I made a control for selecting Date. you can increase or decrease Day,Month or year just by Scrolling MouseWheel. but when I put this control in ScrollViewer MouseWheel will scroll ScrollViewer and MyControl not work properly. I have searched a lot to prevent ScrollViewer from handling MouseWheel but I couldn't.

this is my Xaml:

<ScrollViewer>
    <StackPanel>
         some other elements...

            <controls:DateTimeSelect Width="400" Value="{x:Static system:DateTime.Now}"/>

         some other elements...
    </StackPanel>
</ScrollViewer>
1
  • What do you mean by "not work properly"? Is scrolling not happening at all? Or is it not having any smooth scroll? DateTimeSelect looks like a custom control? How does your view looks like? Can u share those details? Commented Oct 20, 2018 at 14:05

2 Answers 2

1

You can sign up for PreviewMouseWheel event fromScrollViewer and forward it to your DateTimeSelect control.

This code directs the PreviewMouseWheel event within the first ScrollViewer:

private void HandlePreviewMouseWheel(object sender, MouseWheelEventArgs e)
    {
        if (sender is ScrollViewer && !e.Handled)
        {
            e.Handled = true;
            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            eventArg.RoutedEvent = UIElement.MouseWheelEvent;
            eventArg.Source = sender;
            var parent = ((Control)sender).Parent as UIElement;
            parent.RaiseEvent(eventArg);
        }
    } 

For more information, see https://serialseb.com/blog/2007/09/03/wpf-tips-6-preventing-scrollviewer-from/.

To know more about how to use it in your case, further information about contol: DateTimeSelect is required.

Sign up to request clarification or add additional context in comments.

Comments

0

Thank for your answers. I tried so many ways but I realized that ScrollViewer not working as expected. so I made a new project and copied all files from old project to new one step by step and after each change I checked whether scrollerViewer woks properly or not. I am using DevExpress MVVM framework so I have to create and show mainWindow in Bootstarpper and remove StartupUri from App.xaml. I realized that this is where I have problem, every time I set StartupUri and and let App class to show MainWindow nothing is wrong but as I Creating MainWindow manually and show ScrollViewer catches MouseWheel and preventing its children to hadnling it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.