I have to show a list of suggestions to the end user. I want the 1. item on the list to be easiest to read, the 2. item should be a bit smaller and 3. item even smaller.
- Item at index 0 have to be big and all the text is all black
- Item at index 1 have to be a bit smaller and all the text is mainly black but with some gray in it
- Item at index 2 and higher have to be smallish and all the text is grayish
Example
I am using WPF but have not found a way to do this yet.
Currently I have:
<ListView ItemsSource="{Binding MyList}" Height="auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding SomeText}"/>
<Label Grid.Column="1" Content="{Binding MoreText}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
This only generates a flat list were each element is the same size.
I have been looking at AlternationCount + ItemsControl.AlternationIndex, but those will alternate, which is not what I want, I want a special 1. and 2. row, and the rest of the rows are the same.
EDIT SOLUTION Thanks to @Adrian Faciu for the solution.
It looks like this:
<ItemsControl ItemsSource="{Binding MyList}" AlternationCount="1000" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent">
<ItemsControl.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="Red"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}" Value="0">
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="FontSize" Value="20" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}" Value="1">
<Setter Property="Foreground" Value="Yellow"></Setter>
<Setter Property="FontSize" Value="15" />
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Resources>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding MyText}"/>
<Label Grid.Column="1" Content="{Binding AnotherText}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>