如何访问在Silverlight / C#ListBox控件的ScrollViewer中的元素? [英] How do you access the ScrollViewer element of a ListBox control in Silverlight/C#?
问题描述
我想从C#动态改变一个Silverlight列表框的滚动位置,我需要知道如何从C#访问ListBox控件的ScrollViewer中的元素?
I wish to dynamically change the scroll position of a Silverlight ListBox from C#, and I need to know how to access the ScrollViewer element of a ListBox control from C#?
谢谢你们,
杰夫
Thanks guys, Jeff
推荐答案
这是从ListBox类继承的类中,你可以使用受保护GetTemplateChild():
From within a class that inherits from the ListBox class, you can use the Protected GetTemplateChild():
VAR myScrollviewer = myListBox.GetTemplateChild(ScrollViewer中)作为的ScrollViewer;
如果你想通过属性从列表框外部访问这一点,那么暴露的ScrollViewer应该工作,再通过继承。
If you want to access this from outside the ListBox, then exposing the ScrollViewer via a Property should work, again through inheritance.
警告:如果已设置自定义的模板,然后这个ScrollViewer中可能不存在。您可以在上述方法中使用这些模板的ScrollViewer名称,而不是ScrollViewer中的。
CAVEAT: If you have set your own custom template, then this Scrollviewer may not exist. You can use the templates Scrollviewer name instead of the "ScrollViewer" in the method above.
这篇关于如何访问在Silverlight / C#ListBox控件的ScrollViewer中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!