Articles in this section
Category / Section

How to restrict ScrollViewer mouse wheel scrolling, when mouse is over child control loaded in it?

1 min read

ScrollViewer control helps to load, scroll and view child UI (WPF UpDown) elements more than screen bounds. But when mouse point is over its child controls and scroll action is performed, both the child controls and scroll viewer will scroll at the same time. It is possible to handle ScrollViewer wheel scrolling in this scenario and that can be done by using ScrollToVerticalOffset function.

For example

Here we have considered UpDown control as an example.

XAML

<ScrollViewer x:Name="scroll" PreviewMouseWheel="ScrollViewer_MouseWheel"  Focusable="False"> 
  <Grid> 
      <syncfusion:UpDown Height="50" Width="150" x:Name="updown"/> 
      <Button Height="50" Width="150" x:Name="updown1" Margin="175,322,175,-53"/> 
  </Grid> 
</ScrollViewer> 

C#

/// <summary> 
/// Invoked when the mousewheel on the ScrollViewer 
/// </summary> 
private void ScrollViewer_MouseWheel(object sender, MouseWheelEventArgs e) 
{ 
   if(updown.IsMouseOver) 
   { 
     scroll.ScrollToVerticalOffset(scroll.VerticalOffset); 
   } 
} 

Sample: UpDownSample

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied