Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the mouse wheel to work correctly with the Silverlight 4 ScrollViewer

Tags:

silverlight

When I use the following xaml in Silverlight 4, the ScrollViewer will not recognize the mouse wheel unless I click once on the scroll bar thumb, and keep the mouse over the scroll bar, while turning the mouse wheel.

<Grid x:Name="LayoutRoot" Background="White">
    <ScrollViewer>
        <StackPanel Name="stackPanel1">
            <Button Content="Button 1" Width="150" />
            <Button Content="Button 2" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 3" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 4" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 5" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 6" Width="150" Margin="0,20,0,0" />
            <Button Content="Button 7" Width="150" Margin="0,20,0,0" />
        </StackPanel>
    </ScrollViewer>
</Grid>

Has anyone else experience this, and is there any work around?

like image 930
Ian Oakes Avatar asked Jun 07 '10 03:06

Ian Oakes


1 Answers

The resolution here seems to be set a background brush on the ScrollViewer. In my case I chose to use the Transparent brush. It seems to be related to hit testing whereby a control without a brush will never receive any mouse events.

<ScrollViewer Background="Transparent">
like image 121
Ian Oakes Avatar answered Sep 23 '22 04:09

Ian Oakes