我正在使用WPF,我有一个ScrollViewer,想要检测滚动条的水平移动。
我发现了这个,但不知道如何在我的C#代码中使用它。
我不想在我的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 :(得分: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);
}