CollectionView.MoveCurrentTo(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的项设置为 CurrentItem 视图中的项。
public:
virtual bool MoveCurrentTo(System::Object ^ item);
public virtual bool MoveCurrentTo(object item);
abstract member MoveCurrentTo : obj -> bool
override this.MoveCurrentTo : obj -> bool
Public Overridable Function MoveCurrentTo (item As Object) As Boolean
参数
- item
- Object
要设置为 . 的 CurrentItem项。
返回
实现
示例
下面的示例演示如何使用此方法。
// Event handler for the NewColor button
void OnNewColorClicked(object sender, RoutedEventArgs args)
{
Button button = (Button)sender;
ColorItemList colorList = (ColorItemList)button.DataContext;
CollectionView cv = (CollectionView)CollectionViewSource.GetDefaultView((IEnumerable)colorList);
// add a new color based on the current one, then select the new one
ColorItem newItem = new ColorItem((ColorItem)cv.CurrentItem);
colorList.Add(newItem);
cv.MoveCurrentTo(newItem);
}
' Event handler for the NewColor button
Private Sub OnNewColorClicked(ByVal sender As Object, ByVal args As RoutedEventArgs)
Dim button As Button = CType(sender, Button)
Dim colorList As ColorItemList = CType(button.DataContext, ColorItemList)
Dim cv As CollectionView = CType(CollectionViewSource.GetDefaultView(CType(colorList, IEnumerable)), CollectionView)
' add a new color based on the current one, then select the new one
Dim newItem As New ColorItem(CType(cv.CurrentItem, ColorItem))
colorList.Add(newItem)
cv.MoveCurrentTo(newItem)
End Sub
注解
如果未找到指定的项,该方法将 false 返回并 CurrentItem 定位在视图中集合的开头之前。
集合视图支持当前记录指针的概念。 在集合视图中浏览对象时,将移动一个记录指针,以便检索集合中该特定位置存在的对象。 有关详细信息,请参阅数据绑定概述中的“绑定到集合”。
有关视图的当前项的详细信息,请参阅 CurrentItem。