ScrollViewer 上 VerticalOffset 属性的双向绑定? [英] Two-Way Binding Of VerticalOffset Property on ScrollViewer?

查看:25
本文介绍了ScrollViewer 上 VerticalOffset 属性的双向绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Silverlight 3.0 中有一个视图和一个视图模型.

I have a View and a ViewModel in Silverlight 3.0.

该视图包含一个标准的 ScrollViewer,其中包含动态内容.

The view contains a standard ScrollViewer, which contains dynamic content.

根据 ScrollViewer 中的内容,用户可能已经滚动到内容的一半,然后执行一个导致 ScrollViewer 加载新内容的操作,但 ScrollViewer 不会自动滚动到顶部.

Depending on the content within the ScrollViewer, the user could have scrolled half way down the content, and then performed an action that causes the ScrollViewer to load new content, but the ScrollViewer does not automatically scroll to the top.

我希望能够绑定到 VerticalOffset 属性,但它是只读的.关于可附加行为的任何想法?有什么想法吗?

I want to be able to bind to the VerticalOffset property, but it is read-only. Any ideas on attachable behavior? Any ideas?

谢谢.

推荐答案

以下博客文章提供了一个附加行为,该行为公开了滚动查看器的垂直/水平偏移,以便您可以绑定到它们,或在代码中设置它们:

The following blog post provides an attached behaviour that exposes the vertical / horizontal offsets of a scrollviewer so that you can bind to them, or set them in code:

http://blog.scottlogic.com/2010/07/21/exposing-and-binding-to-a-silverlight-scrollviewers-scrollbars.html

这允许以下标记:

<ScrollViewer 
    local:ScrollViewerBinding.VerticalOffset="{Binding YPosition, Mode=TwoWay}"
    local:ScrollViewerBinding.HorizontalOffset="{Binding XPosition, Mode=TwoWay}">
    <!-- Big content goes here! -->
</ScrollViewer>

这篇关于ScrollViewer 上 VerticalOffset 属性的双向绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆