WPF: Scrolling the screen using the scrollwheel when mouse is over a listbox.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Telinstryata
    New Member
    • Nov 2008
    • 11

    WPF: Scrolling the screen using the scrollwheel when mouse is over a listbox.

    I have a WPF user control with the following...

    a) A ListBox on the left of the screen
    b) A TextBox on the right of the screen
    c) A ScrollViewer around both

    When my mouse is over the TextBox and I use the scrollwheel, the TextBox scrolls. When I scroll to the bottom of the TextBox the ScrollViewer then takes over and scrolls.

    When my mouse is over the ListBox and I use the scrollwheel, the ListBox scrolls. When I scroll to the bottom of the ListBox the ScrollViewer does not take over and does not scroll.

    The following is a little test window that shows this functionality (my real code is far to long to use as an example)

    Code:
    <Window x:Class="Scroll"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Scroll" Height="100" Width="300">
        <Grid>
            <ScrollViewer Name="ScrollViewer1">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ListBox MaxHeight="200" VerticalAlignment="Top" HorizontalAlignment="Left">
                        <ListBoxItem Content="Item 0" FontSize="30" />
                        <ListBoxItem Content="Item 1" FontSize="30" />
                        <ListBoxItem Content="Item 2" FontSize="30" />
                        <ListBoxItem Content="Item 3" FontSize="30" />
                        <ListBoxItem Content="Item 4" FontSize="30" />
                        <ListBoxItem Content="Item 5" FontSize="30" />
                        <ListBoxItem Content="Item 6" FontSize="30" />
                        <ListBoxItem Content="Item 7" FontSize="30" />
                    </ListBox>
                    
                    <TextBox Height="200" Grid.Column="1" TextWrapping="Wrap" FontSize="30"
                             VerticalScrollBarVisibility="Auto">This is some text used to fill up the text box with small words. blah blah blah blah blah.</TextBox>
                </Grid>
            </ScrollViewer>
        </Grid>
    </Window>
    Is there any way to get the scroll event on the ListBox to be passed onto the ScrollViewer just like it is with the TextBox
Working...