如何在Windows.UI.Xaml中的T​​extBoxes中同步滑块

时间:2015-09-29 02:09:47

标签: c# textbox slider synchronize

如何在Windows.UI.Xaml中的T​​extBoxes中同步垂直滑块?

只是复制并粘贴以下代码不起作用。

    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同时滚动。

0 个答案:

没有答案