Search code examples
xamldatatemplatedatatrigger

Item in ItemsControl to have different style than all the others which are in DataTemplate


Here's my xmal code:

<ItemsControl ItemsSource="{Binding myObjects}" >
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel HorizontalAlignment="Center">                            
                <TextBlock FontSize="24pt" FontWeight="Bold" TextAlignment="Center" Text="{Binding MyClassTranslation.MyClassName[0]}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

The problem which I'm facing is that I want the first item in the ItemsControl to have different style than the ones in the DataTemplate. How do I do this? I tried using data triggers but with no success, I don't know how to apply it to the first item.


Solution

  • I solved my problem by using DataTemplateSelector. Thanks to @Rob Jacobs. I used this tutorial/