如何获取CollectionViewSource的第一个元素?

Dar*_*Zon 1 c# silverlight wpf xaml microsoft-metro

我记得看过一些代码xaml,可以从集合中获取第一个元素(如索引x [0]).

这是我的Resources的CollectionViewSource.

<CollectionViewSource
            x:Name="groupedItemsViewSource2"
            Source="{Binding Posters}"
            ItemsPath="Posters" />
Run Code Online (Sandbox Code Playgroud)

如果我在列表框中显示它,它加载它!

<ListBox ItemsSource="{Binding Source={StaticResource groupedItemsViewSource2}}" />
Run Code Online (Sandbox Code Playgroud)

但是现在,我只想通过xaml获得第一个元素.有可能这样做吗?

Til*_*lak 7

我遇到了类似的问题,我做的是调用MoveCurrentToFirst(在ViewModel中)

`SelectedIndex = 0(在XAML中的ListBox上),是另一种方式,但是当Collection视图源不保存任何数据时它失败了.