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

编程入门 行业动态 更新时间:2024-10-14 10:45:18
本文介绍了如何获得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的第一个元素?

本文发布于:2023-11-25 10:39:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   如何获得   元素   CollectionViewSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!