代码之家  ›  专栏  ›  技术社区  ›  Andy Clarke

wpf-如何在scrollviewer中点击测试滚动条?

  •  0
  • Andy Clarke  · 技术社区  · 17 年前

    有人能告诉我如何在WPF中测试scrollviewer的滚动条吗?

    谢谢

    安迪

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <StackPanel>
            <ScrollViewer Name="myScrollViewer" Width="280" Height="200" MouseMove="ScrollViewer_MouseMove" >
    
    
            </ScrollViewer>
    
            <TextBox Name="myTextBox"></TextBox>
        </StackPanel>
    </Window>
    

    代码隐藏。。。

    using System.Windows.Input;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1
        {
            public Window1()
            {
                InitializeComponent();
            }
    
            private void ScrollViewer_MouseMove(object sender, MouseEventArgs e)
            {
                myTextBox.Text = e.GetPosition(myScrollViewer).X + "," + e.GetPosition(myScrollViewer).Y;
            }
    
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Nicolas Dorier    17 年前

    具有 VisualTreeHelper.HitTest ,MouseEventArgs与scrollviewer相关,因此第一个参数是scrollviewer。 然后使用 PointHitTestParameter 与鼠标的坐标相同。