如何获得CollectionViewSource的第一个元素? [英] How to get the first element of a CollectionViewSource?
问题描述
我记得看到一些代码XAML在哪里可以得到的第一个元素(如索引X [0])的集合。
I remember seen some code xaml where can get the first element (like an index x[0]) from a collection.
这是从资源我CollectionViewSource。
This is my CollectionViewSource from Resources.
<CollectionViewSource
x:Name="groupedItemsViewSource2"
Source="{Binding Posters}"
ItemsPath="Posters" />
如果我在一个列表框中显示这一点,就装好了!
If I display this in a listbox, it loaded it!
<ListBox ItemsSource="{Binding Source={StaticResource groupedItemsViewSource2}}" />
但是现在,我只是想通过XAML来获得的第一个元素。是否可以这样做呢?
But right now, I just want to get the first element through xaml. Is it possible doing this?
推荐答案
我面临着类似的问题,我所做的就是调用的 MoveCurrentToFirst
(在视图模型)
I faced similar issue, and what i did was to call MoveCurrentToFirst
(in ViewModel)
的`的SelectedIndex = 0
(在XAML列表框),另一种方式,但是当集合查看源文件不包含任何数据它失败了。
`SelectedIndex=0 (on ListBox in XAML), was another way but it was failing when Collection view source does not hold any data.
这篇关于如何获得CollectionViewSource的第一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!