Reputation: 13
My issue is that I have a very simple Listbox with a list of items. I noticed that when I disable the ScrollViewer from the MainPage_Loaded event, the ScrollViewer can be re-enabled by swiping the Listbox diagonally at any direction.
I have tried setting the property from XAML:
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" ...../>
I also tried to do it from code:
var myScrollviewer = VisualTreeHelper.GetChild(MyListBox, 0) as ScrollViewer;
myScrollviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
myScrollviewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
Straight vertical and horizontal swipe do indicate that the ScrollViewer is disabled but when I swipe diagonally without lifting my hand from the screen, the items in the listbox start scrolling up and down. This behavior seems like a bug!
Can someone tell me how to totally disable the scrollviewer so diagonal swiping doesn't temporarily re-enable the scrollviewer?
This behavior is affecting my underline task of dragging an item while the scrollviewer is disabled.
Thanks
Upvotes: 1
Views: 1848
Reputation: 69372
That's interesting, haven't noticed that before. It may be a bug but to get around it try setting the ScrollViewer's ManipulationMode property to Control
to let the OS know that you'll be handling the ScrollViewer at the control level rather than letting the system handle it.
<ListBox ScrollViewer.ManipulationMode="Control"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" .../>
However, when you re-enable it, set the ManipulationMode
back to System
for a smoother scrolling.
Update based on comments
To re-enable the scrollviewer, do this
var myScrollviewer = VisualTreeHelper.GetChild(MyListBox, 0) as ScrollViewer;
myScrollviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
myScrollviewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
//key part - use SetValue to set ManipluationMode.System/Control
myScrollviewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.System);
If you need to disable it again, you can do the same thing but with the disabled properties and ManipulationMode.Control
.
var myScrollviewer = VisualTreeHelper.GetChild(MyListBox, 0) as ScrollViewer;
myScrollviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
myScrollviewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
//key part - use SetValue to set ManipluationMode.System/Control
myScrollviewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.Control);
Upvotes: 1