2013-06-11 46 views
0

我正在使用WPF,我有一個ScrollViewer,並希望檢測滾動條的水平移動。WPF:滾動條移動檢測

我發現這個,但不知道如何在我的C#代碼中使用它。

http://msdn.microsoft.com/en-us/library/system.windows.forms.scrolleventargs.scrollorientation%28v=vs.85%29.aspx

我不想因爲我使用別的東西檢測我的ScrollViewer雙擊或點擊。

<ScrollViewer x:Name="coordinateScroll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="75,0,0,0" Width="1125" Height="750" Background="Transparent" MouseWheel="coordinateSystemBackground_MouseWheel" MouseDoubleClick="coordinateScroll_MouseDoubleClick " ScrollChanged="coordinateScroll_ScrollChanged" > 
        <Canvas x:Name="coordinateSystem" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="Cross" UseLayoutRounding="False" Width="1125" Height="720" Background="Transparent" MouseWheel="coordinateSystemBackground_MouseWheel" > 
        </Canvas> 
       </ScrollViewer> 
+0

你剛纔問此相同的問題在這裏: http://stackoverflow.com/questions/16963003/wpf-get-an-event-on-the-scrollbar-from-scrollviewer –

回答

1

coordinateScroll_ScrollChanged是什麼問題在您的XAML中?

該處理程序將具有offset屬性的事件參數。

private void coordinateScroll_ScrollChanged(object sender, ScrollChangedEventArgs e) 
{ 
    var status = "ExtentHeight is now " + e.ExtentHeight.ToString(); 
    status += "\nExtentWidth is now " + e.ExtentWidth.ToString(); 
    status += "\nExtentHeightChange was " + e.ExtentHeightChange.ToString(); 
    status += "\nExtentWidthChange was " + e.ExtentWidthChange.ToString(); 
    status += "\nHorizontalOffset is now " + e.HorizontalOffset.ToString(); 
    status += "\nVerticalOffset is now " + e.VerticalOffset.ToString(); 
    status += "\nHorizontalChange was " + e.HorizontalChange.ToString(); 
    status += "\nVerticalChange was " + e.VerticalChange.ToString(); 
    MessageBox.Show(status); 
} 
+0

此事件被稱爲很多次(因爲我操縱了畫布的寬度),因此我只想檢測滾動條的移動 – user2261524

+0

嗯,您可能會在佈局被調整大小的時候抑制通知。 –