0

I've got a page in a TabControl with a lot of content. I can scroll the whole page just with the mouse wheel almost anywhere on the page.

But this behavior breaks whenever when the mouse is over one ListBox on the page. Whenever I'm above that the wheel has no effect. It's annoying and I would like to fix it.

As a diagnostic, I tried adding handlers to the ListBox for PreviewMouseWheel and MouseWheel. I get the former, but never the latter. So clearly the ListBox is eating the wheel messages, preventing them from escaping.

I need to let those wheel messages escape to the containing page so that it will scroll normally. But at the same time I still need it to be able handle mouse clicks and selection so I cannot change IsHitTestVisible or anything like that. (I am using a ListBox because I want multiple selection)

(If this were a mouse button handler, I would try to override the virtual OnMouseLeftButton down function, call the base class and then re-set the Handled property of the event handler. But there are no such corresponding virtual functions for wheel events)

Is there some property I can set to turn off this behavior? Maybe some event handler I can write? I feel like this should be easy but I cannot figure it out.

I don't think it matters but here is the XAML of the ListBox on the page

<ListBox Margin="20, 5" DockPanel.Dock="Top" SelectionMode="Multiple"
    ItemsSource="{Binding ResettableSettings}">
    <ListBox.ItemTemplate>
        <DataTemplate DataType="{x:Type svc:ISettingsGroup}">
            <StackPanel>
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="20"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="10"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="10"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Name}" FontWeight="Bold" 
                        Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"/>

                    <TextBlock Text="{x:Static res:ConfigureStrings.Settings}" 
                        Grid.Row="2" Grid.Column="0"/>
                    <TextBlock Text="{Binding Description}"
                        Grid.Row="2" Grid.Column="2"/>
                    <TextBlock Text="Effects"
                        Grid.Row="4" Grid.Column="0"/>
                    <TextBlock Text="{Binding ResetEffects}"
                        Grid.Row="4" Grid.Column="2"/>
                 </Grid>
           </StackPanel>
        </DataTemplate>

    </ListBox.ItemTemplate>
</ListBox>
Joe
  • 5,394
  • 3
  • 23
  • 54
  • Makes no sense, what if you want to scroll into the list box then? This behavior is expected and is the way to go. The solution to your problem is to rework your interface, try using an expander instead of a listbox. – aybe Mar 27 '22 at 10:08
  • It makes perfect sense. I need the option to disable the behavior. I won't ever need scrolling with this ListBox, and I need `ListBox` because it's the only `ItemsControl` supports multiple selection (aside from `GridView` that doesn't work for reasons beyond the scope of this question). Show me another `ItemsControl` that supports multiple selection and doesn't have this problem I could rework it that way. Expander does not. Fortunately the solution for which they closed this question appears to be good, though less than ideal. – Joe Mar 27 '22 at 14:47

0 Answers0