당신은 당신이 SetVerticalOffset
메소드를 호출 이후에 VerticalOffset
속성 값을 잡을 수 있도록 내부적으로 ListBox
사용하는 ScrollViewer
의 보류를 얻을 필요가있다.
이렇게하려면 내부를 구성하는 시각적 트리를 통해 ListBox
에서 연락해야합니다.
내가 (내가 블로그에 올려 나는 그것을 계속 반복 돼했기 때문에) 프로젝트에 추가해야이 편리한 확장 클래스를 사용 : -
public static class VisualTreeEnumeration
{
public static IEnumerable<DependencyObject> Descendents(this DependencyObject root, int depth)
{
int count = VisualTreeHelper.GetChildrenCount(root);
for (int i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(root, i);
yield return child;
if (depth > 0)
{
foreach (var descendent in Descendents(child, --depth))
yield return descendent;
}
}
}
public static IEnumerable<DependencyObject> Descendents(this DependencyObject root)
{
return Descendents(root, Int32.MaxValue);
}
public static IEnumerable<DependencyObject> Ancestors(this DependencyObject root)
{
DependencyObject current = VisualTreeHelper.GetParent(root);
while (current != null)
{
yield return current;
current = VisualTreeHelper.GetParent(current);
}
}
}
이 사용할 수와 ListBox
(그리고 그 외의 다른 모든 UIElement는 새로운 확장 방법 인 Descendents
과 Ancestors
을 얻습니다. 그것들을 Linq와 결합하여 물건을 검색 할 수 있습니다. 이 경우 다음을 사용할 수 있습니다. -
ScrollViewer sv = SomeListBox.Descendents().OfType<ScrollViewer>().FirstOrDefault();
감사합니다. 나는 컨트롤의 메이크업이 이런 식으로 움직일 수 있다는 것을 깨닫지 못했다. –
어떻게 정보를 언제 사용하는지 어떻게 알 수 있습니까? 어떻게 페이지가 농구대를 뛰어 넘지 않고 묘비에서 복원되고 있다는 것을 알 수 있습니까? – Roger
@Roger :이 MSDN 항목을 읽었습니다. http://msdn.microsoft.com/en-us/library/ff967548(v=VS.92).aspx – AnthonyWJones