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>
PS 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.