简体   繁体   中英

How to skip showing the first item in the ItemsSource that bound with a ItemsControl?

I am using ItemsControl to show a list of objects. Is it possible, not to show first item of the list ? I tried creating a new property in my ViewModel which will skip the first element.

public ObservableCollection<ConditionElement> ExtraConditionLiteral
{
    get 
    { 
        return ConditionElementList.Skip(0) as ObservableCollection<ConditionElement>; 
    }
}

But this is not working. Is there any way Ican skip the first element while binding with ItemsSource ?

I may provide another idea. You can write your itemscontrol's item template like

<Label Visibility="{Binding RelativeSource={RelativeSource PreviousData},Converter={StaticResource NullToVisibilityConverter}}"/>

So for the first element, the previous element is null, and you need to implement the NullToVisibilityConverter to return Visibility.Collapsed when input is null. I think this Converter is very common.

In your code you doesn't skip the element actually. You should pass the count of shipped elements instead of the index.

Try this:

return new ObservableCollection<ConditionElement>(ConditionElementList.Skip(1));

But you should pay an attention to order of your collection as well.

Enumerable.Skip Method

The input param of Skip in LINQ is actually a "Count" Skip(0) actually telling the LINQ to do nothing at all.

Try Skip(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM