WPF:滚动条移动检测

时间:2013-06-11 13:39:45

标签: c# wpf scrollviewer

我正在使用WPF,我有一个ScrollViewer,想要检测滚动条的水平移动。

我发现了这个,但不知道如何在我的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>

1 个答案:

答案 0 :(得分:1)

您的XAML中的coordinateScroll_ScrollChanged事件有什么问题?

此处理程序将具有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);
}