Removing default Scroll bar from UWP app using XAML

Viewed 113

In my UWP app, I have a datagrid which already has a separate scroll bar but I am also getting the app default scroll bar which is I tried to hide and disable in following way:

ScrollViewer.VerticalScrollBarVisibility="Hidden" 
ScrollViewer.VerticalScrollMode="Disabled"

but still on hovering I am getting a default scroll bar. Please refer to the attached image.

Could anyone help me in removing the default scroll bar?

App Image

1 Answers

Please refer the source code, it was not implemented with ScrollViewer, we can't get the scrollviewer instance. for this scenario, you could detect vertical scrollbar with visual tree helper and hidden it, for more please refer the following code.

var scrollbar = MyFindDataGridChildOfType<ScrollBar>(MyDataGrid);
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
    scrollbar.Visibility = Visibility.Collapsed;
});


public static T MyFindDataGridChildOfType<T>(DependencyObject root) where T : class
{
    var MyQueue = new Queue<DependencyObject>();
    MyQueue.Enqueue(root);
    while (MyQueue.Count > 0)
    {
        DependencyObject current = MyQueue.Dequeue();
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(current); i++)
        {
            var child = VisualTreeHelper.GetChild(current, i);
            var typedChild = child as T;
            if (typedChild != null)
            {
                return typedChild;
            }
            MyQueue.Enqueue(child);
        }
    }
    return null;
}
Related