我想滚动 3 个不同的TextBoxes
.
我在这里找到了一些方法。但在 VS2012 中我不能使用Windows.Forms
非常烦人的。我确实尝试添加引用,但我发现没有Windows.Form
,这是屏幕截图:
所以我找到了一个使用滚动条的想法,可以吗?
为了使用windows.forms
命名空间,您需要将System.windows.forms
库添加到项目中:右键单击References
(解决方案资源管理器)-> Add Reference
-> .NET
-Tab -> 选择System.Windows.Forms
并单击确定。
然后,您可以在需要的每个文件中导入 System.Windows.Forms 命名空间。
http://www.gbogea.com/2009/07/08/how-to-keep-two-scrollviewers-in-sync-in-wpf
有代码。如果站点出现故障,将在此处复制粘贴作为镜像:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" Name="scrollViewerLeft" ScrollChanged="scrollViewerLeft_ScrollChanged">
<ListBox>
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
...
<ListBoxItem>100</ListBoxItem>
</ListBox>
</ScrollViewer>
<ScrollViewer Grid.Column="1" Name="scrollViewerMiddle">
<ListBox>
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
...
<ListBoxItem>100</ListBoxItem>
</ListBox>
</ScrollViewer>
<ScrollViewer Grid.Column="2" Name="scrollViewerRight">
<ListBox>
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
...
<ListBoxItem>100</ListBoxItem>
</ListBox>
</ScrollViewer>
</Grid>
以及背后的代码:
private void scrollViewerLeft_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
scrollViewerMiddle.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
scrollViewerRight.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
}
private void scrollViewerMiddle_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
scrollViewerLeft.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
scrollViewerRight.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
}
private void scrollViewerRight_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
scrollViewerLeft.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
scrollViewerMiddle.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
}