Word:SyncScrollingSideBySide 和 ScrollIntoView
我们的 Word 插件的一项功能是并排显示两个文档窗口。用户可以双击左侧文档中的段落以将右侧文档中的关联段落滚动到视图中。当我们这样做时,如果在双击之前启用了同步滚动,我们希望重新启用同步滚动。我们正在做这样的事情:
private void LineUpParagraphs()
{
// Unlock the views so we can scroll them independently.
bool wasSyncEnabled = this.originalDocument.Document.Windows.SyncScrollingSideBySide;
this.originalDocument.Document.Windows.SyncScrollingSideBySide = false;
// Scroll corresponding original paragraph into view.
this.originalDocument.Document.Windows[1].ScrollIntoView(
this.CurrentOriginalParagraph.Range);
// Re-enable synchronous scrolling if it was enabled before.
if (wasSyncEnabled)
{
this.originalDocument.Document.Windows.SyncScrollingSideBySide = true;
}
}
完成此操作后,所需的范围将在原始(我们应用程序的右侧)文档中显示,但是只要您滚动任一窗口,右侧窗口就会跳回来到其原始位置。
我们尝试过但不起作用的事情:
- 在所有应用程序窗口上设置 SyncScrollingSideBySide 属性,而不仅仅是两个比较文档之一。
- 再次切换该属性。
我们使用 SendKeys 来模拟单击“同步滚动”按钮。 (如果您不以编程方式重新启用同步,然后自己单击该按钮,则当您滚动时,右侧文档不会跳回其原始位置)。但这实际上并不是一个可接受的解决方案 - 例如,根据我们的加载项选项卡是否处于活动状态,它是不一致的。有时它会起作用,有时它会再次切换同步滚动,这会惹恼客户。有更好的办法吗?
注意:当左侧文档比右侧文档(正在滚动的文档)长时,就会出现此问题。
One feature of our Word add-in shows two document windows side-by-side. The user can double-click a paragraph in the left-hand document to scroll an associated paragraph in the right-hand document into view. When we do this, we want to re-enable Synchronous Scrolling if it was enabled before the double-click. We're doing something like this:
private void LineUpParagraphs()
{
// Unlock the views so we can scroll them independently.
bool wasSyncEnabled = this.originalDocument.Document.Windows.SyncScrollingSideBySide;
this.originalDocument.Document.Windows.SyncScrollingSideBySide = false;
// Scroll corresponding original paragraph into view.
this.originalDocument.Document.Windows[1].ScrollIntoView(
this.CurrentOriginalParagraph.Range);
// Re-enable synchronous scrolling if it was enabled before.
if (wasSyncEnabled)
{
this.originalDocument.Document.Windows.SyncScrollingSideBySide = true;
}
}
After doing this, the desired range is in view in the original (right-hand for our app) document, but as soon as you scroll either window, the right-hand window jumps back to its original position.
Things we've tried that didn't work:
- Set the SyncScrollingSideBySide property on all of the Application windows rather than just one of the two compare documents.
- Toggle the property an additional time.
We've resorted to SendKeys to simulate a click on the Synchronous Scrolling button. (If you don't re-enable the sync programatically, then click the button yourself, the right-hand document doesn't jump back to its original position when you scroll). This isn't really an acceptable solution, though--it is inconsistent for example depending on whether our add-in's tab is active. Sometimes it works, sometimes it toggles the sync scrolling an additional time which will annoy the customer. Is there a better way?
Note: The issue occurs when the left-hand document is longer than the right-hand document (the one being scrolled).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论