I have a ScrollViewer
with an ItemPresenter
inside.
The ItemsPresenter
contains a few dropdowns, and when I open one of those, I'd like to disable the parent ScrollViewer
's scroll and only re-enable it only when the dropbox is closed.
By saying "disable" I mean prevent scrolling at all (even with the mouse wheel).
I've tried to set the VerticalScrollBarVisibility
to Disabled
like this:
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Disabled">
<ItemsPresenter />
</ScrollViewer>
but that doesn't work either.
It just hides the scrollbar, but the mouse wheel still works.
So, is there a way to completely disable the ScrollViewer
's scroll?
Here is the full code that I have:
<ListView.Template>
<ControlTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="{Binding IsScrollEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ListView.Template>
P.S. There are lots of some similar questions like this and this, but none of them is the one I wanted.
You can disable scrolling by handling the PreviewMouseWheel
event for the ScrollViewer
.
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="{Binding IsScrollEnabled, Converter={StaticResource BoolToVisibilityConverter}}"
PreviewMouseWheel="UIElement_OnPreviewMouseWheel">
<ItemsPresenter />
</ScrollViewer>
private void UIElement_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With