In our .NET MAUI application, we aim to determine if the Microsoft.UI.Xaml.Controls.Primitives.ScrollBar was pressed in WinUI platform. We've attempted to retrieve it by wiring PointerPressed and iterating through the parent of the OriginalSource from PointerRoutedEventArgs until encountering the scrollbar. Also Move action can be detected in content touch, while scrolling using scrollbar. Are there alternative approaches to obtain the scrollbar instance, in platform specific (WinUI) or .NET Maui?
// PointerPressed event.
private void PointerPressed(object sender, PointerRoutedEventArgs e)
{
if ((e.OriginalSource is Microsoft.UI.Xaml.Shapes.Rectangle || e.OriginalSource is Microsoft.UI.Xaml.Controls.Grid))
{
if (this.IsScrollBarPressed(e.OriginalSource))
{
return;
}
}
}
private bool IsScrollBarPressed(object touchElement)
{
DependencyObject parent = VisualTreeHelper.GetParent(touchElement as DependencyObject);
while (parent != null)
{
parent = VisualTreeHelper.GetParent(parent);
if (parent is ScrollBar)
{
return true;
}
}
return false;
}