Hi,
你可以通过VisualTreeHelper拿到GridView模板中的ScrollViewer,之后通过ScrollViewer中的HorizontalOffset拿到现在滚动条所在的位置,拿ScrollViewer的代码:
public static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
string controlName = child.GetValue(Control.NameProperty) as string;
if (controlName == name)
{
return child as T;
}
else
{
T result = FindVisualChildByName<T>(child, name);
if (result != null)
return result;
}
}
return null;
}
使用的时候:
ScrollViewer sv = FindVisualChildByName<ScrollViewer>(this.gv, "ScrollViewer");
就可以拿到ScrollViewer,偏移量通过HorizontalOffset可以计算出来。
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.