2009-09-18 49 views
0

有人可以告訴我如何在WPF中測試scrollviewer的滾動條嗎?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

隨着VisualTreeHelper.HitTest,該MouseEventArgs是relatif到ScrollViewer中,所以第一個參數是您的ScrollViewer。 然後使用PointHitTestParameter與MouseEventArgs的座標。

+0

謝謝你的 – 2009-09-28 16:52:30