如何同步两个滚动条? [英] How can I synchronize two scroll bars?
本文介绍了如何同步两个滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想同步两个滚动条;当用户向上/向下滚动 2 自动将滚动 1 设置为相同的位置时.scroll2 是 RichTextBox
的实例,scroll1 是 ListView
的实例.我不知道该怎么做.
I want to sync two scroll bars; when the user up/down scroll2 auto set scroll1 with same postion. The scroll2 is an instance of an RichTextBox
and scroll1 is an instance of ListView
. I have no idea how do this.
我认为现在更接近了.这是我当前的 XAML 代码:
I think is closer now. Here is my current XAML code:
<RichTextBox ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" Name="TextInput" AcceptsReturn="True" TextChanged="TextChangedEventHandler" Margin="0,23,0,9" ScrollViewer.ScrollChanged="OnScrollChangedHandler" HorizontalScrollBarVisibility="Visible" Grid.RowSpan="2" Grid.ColumnSpan="9" HorizontalAlignment="Right" Width="432.493">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
<ScrollViewer Name="ScrollRow" VerticalScrollBarVisibility="Visible" ScrollViewer.ScrollChanged="OnRowsScrollChangedHandler" ScrollViewer.HorizontalScrollBarVisibility="Visible" Grid.RowSpan="2" Margin="0,23,0,7.02" HorizontalAlignment="Left" Width="40">
<StackPanel Name="pScrollRow">
<ListView Margin="0,23,0,9" Name="Rows">
1.
</ListView>
</StackPanel>
</ScrollViewer>
C# 代码:
// ...
private void OnScrollChangedHandler(object sender, ScrollChangedEventArgs e)
{
((IScrollInfo)pScrollRow).SetHorizontalOffset(e.HorizontalOffset);
}
推荐答案
我建议你添加元素绑定来同步值,这样你就不需要任何代码.以下是有关 MSDN 的详细信息元素绑定.
I would suggest you to add Element binding to sync the values, so you do not need to any code. Here's the details on MSDN about the element binding.
这篇关于如何同步两个滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文