ListCollectionView.CurrentPosition setter

时间:2013-03-22 16:08:50

标签: wpf view setter listcollectionview

ListCollectionView有一个属性获取当前位置(CurrentPosition):

http://msdn.microsoft.com/en-us/library/system.windows.data.collectionview.currentposition.aspx

但是这个属性是只读的。

获取(可选择排序和过滤)视图中CurrentItem的序号位置。

那么如何设置当前位置呢?我希望这不涉及行为......

我需要滚动到ListView或DataGrid的顶部,在我看来,它应该可以轻松设置一个属性,如实现它,而不会进入视图的内容。

提前致谢。

更新

目前这是我自己的解决方法 - 但是当它想要使用MVVM(使用F#)时它会被解雇:

let linesControl = context.Window.FindName("ObjectListView") :?> ListView
let scrollBorder = VisualTreeHelper.GetChild(linesControl, 0) :?> Border
let scrollViewer = scrollBorder.Child :?> ScrollViewer
scrollViewer.ScrollToVerticalOffset(0.0)

2 个答案:

答案 0 :(得分:2)

我使用的基本上是attached property来解决只读,不可绑定的属性(即使大多数时候你不需要编写,绑定也失败了)..

本文解决了ActualWidth / ActualHeight ...

的类似问题

http://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/

...您可以在那里下载代码/示例(或http://dl.dropbox.com/u/39657172/Blog/PushBindingInStyleDemo.zip)。

你用来绑定的东西就像......

<pb:PushBindingManager.PushBindings>
    <pb:PushBinding TargetProperty="CurrentPosition" Path="YourPositionProperty"/>
</pb:PushBindingManager.PushBindings>  

我没有真正尝试过你的例子 - 但从外观上看 - 如果已经有CurrentPosition那么应该以相同的方式工作。


另外,如果需要,可以查看前面这篇文章以获取更多详细信息(如何在Style等中进行处理)...

Get focused MenuItem in submenu WPF

(免责声明:不是我的文章 - 我只是一个感恩的用户:)

答案 1 :(得分:1)

您可以使用

1)MoveCurrentToPosition(int position) 见:msdn

2)MoveCurrentTo(Object item) 见:msdn

3)MoveCurrentToFirst()

4)MoveCurrentToLast()

...