我想滚动3个不同的TextBoxes
。
我在here找到了一些方法。但在VS2012中,我无法使用非常烦人的Windows.Forms
。我确实尝试添加引用,但我发现没有Windows.Form
这是截图:
所以我发现使用滚动条的想法,是否可能?
答案 0 :(得分:1)
要使用windows.forms
命名空间,您需要将System.windows.forms
库添加到项目中:右键单击References
(解决方案资源管理器) - > Add Reference
- > .NET
- 标签 - >选择System.Windows.Forms
,然后单击“确定”。
然后,您可以在每个需要它的文件中导入System.Windows.Forms命名空间。
答案 1 :(得分:1)
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);
}