I\'d like to change the properties of a ScrollViewer of a ListBox from C#.
I found this question here on Stackoverflow. I took the accepted
Here's another reworked and generic version of @punker76's answer for C# 6:
public static class VisualExtensions
{
public static T FindVisualDescendant(this Visual element) where T : Visual
{
if (element == null)
return null;
var e = element as T;
if (e != null)
return e;
(element as FrameworkElement)?.ApplyTemplate();
var childrenCount = VisualTreeHelper.GetChildrenCount(element);
for (var i = 0; i < childrenCount; i++)
{
var visual = VisualTreeHelper.GetChild(element, i) as Visual;
var foundElement = visual.FindVisualDescendant();
if (foundElement != null)
return foundElement;
}
return null;
}
}