Search code examples
c#wpfsilverlightxamlmicrosoft-metro

How to get the first element of a CollectionViewSource?


I remember seen some code xaml where can get the first element (like an index x[0]) from a collection.

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}}" />

But right now, I just want to get the first element through xaml. Is it possible doing this?


Solution

  • I faced similar issue, and what i did was to call MoveCurrentToFirst (in ViewModel)

    SelectedIndex=0 (on ListBox in XAML), was another way but it was failing when Collection view source does not hold any data.