如何在Windows.UI.Xaml中的TextBoxes中同步垂直滑块?
只是复制并粘贴以下代码不起作用。
public static T MyFindTextBoxChildOfType<T>(DependencyObject root) where T : class
{
var MyQueue = new Queue<DependencyObject>();
MyQueue.Enqueue(root);
while (MyQueue.Count > 0)
{
DependencyObject current = MyQueue.Dequeue();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(current); i++)
{
var child = VisualTreeHelper.GetChild(current, i);
var typedChild = child as T;
if (typedChild != null)
{
return typedChild;
}
MyQueue.Enqueue(child);
}
}
return null;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
ScrollViewer myscrollviewer = MyFindTextBoxChildOfType<ScrollViewer>(TextBox1);
myscrollviewer.ViewChanged += myscrollviewer_ViewChanged;
}
public void myscrollviewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
ScrollViewer testScrollViewer = sender as ScrollViewer;
double VerticalOffset = testScrollViewer.VerticalOffset;
}
我想要的是有三个TextBox,其中一个是滚动的,其余的TextBox同时滚动。