Silverlight ScrollViewer 初始水平偏移
我有一个关于 HorizontalOffset 属性设置的问题(使用 ScrollToHorizontalOffset 方法)。
启动我的应用程序后,滚动查看器的内容是动态创建的(即我在设计时不知道其范围)。然后我想设置scrollviewer控件的水平偏移,但是当时它的可滚动宽度返回为0。在scrollviewer上调用UpdateLayout也没有帮助。
我目前正在解决这个问题,方法是在渲染事件中检查滚动查看器控件的 ScrollableWidth 属性,并在 ScrollableWidth > 时立即调用 ScrollToHorizontalOffset 。 0.
这工作正常,但会导致在“渲染”位置调整之前短暂显示错误的初始位置。
我可以做些什么来强制更新滚动查看器,以便我可以设置其水平偏移而无需麻烦?
提前致谢!
I have a question regarding the setting of the HorizontalOffset-property (using the ScrollToHorizontalOffset method).
Upon starting my application, the content for the scrollviewer is dynamically created (i.e. I do not know its extent during design-time). I then want to set the horizontal offset of the scrollviewer control, however at that time its scrollable width is returned as 0. Calling UpdateLayout on the scrollviewer does not help either.
I am currently working around this issue by checking the ScrollableWidth property of the scrollviewer control in the rendering event and make a call to ScrollToHorizontalOffset as soon as ScrollableWidth > 0.
This works fine but leads to a short display of the wrong inital position, before in "rendering" the position is adjusted.
Is there anything I can do to force an update on the scrollviewer so that I can set its horizontal offset without this hassle?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将滚动查看器中内容控件的不透明度设置为 0。调用 ScrollToHorizontalOffset 后,将内容控件的不透明度设置为 1。这样,在正确定位之前实际上看不到任何内容。
Set the opacity of the Content control in the scroll viewer to 0. When you've called ScrollToHorizontalOffset then set the content control's opacity to 1. That way no content is actually seen until its positioned correctly.
在加载子内容之前,可滚动高度/宽度将为零。在那之前,它不知道它需要有多大——因此值为 0。
Scrollable Height/Width will be zero until the child content is loaded. Until then, it doesn't know how big it needs to be - thus the value of 0.