Use Rectangles to fill rows first and then add data to them.
<Grid Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Rectangle Grid.Row="0" Fill="AliceBlue" /> <TextBlock Grid.Row="0" Text="Row 1" HorizontalAlignment="Center"/> <Rectangle Grid.Row="1" Fill="AntiqueWhite" /> <TextBlock Grid.Row="1" Text="Row 2" HorizontalAlignment="Center"/> <Rectangle Grid.Row="2" Fill="AliceBlue" /> <TextBlock Grid.Row="2" Text="Row 3" HorizontalAlignment="Center"/> <Rectangle Grid.Row="3" Fill="AntiqueWhite" /> <TextBlock Grid.Row="3" Text="Row 4" HorizontalAlignment="Center"/> </Grid>
Edit: If you are loading an unknown number of elements, then I think you need something like an element control to load them. Then you can use the alternationcount parameter and triggers to handle the alternating color.
<ItemsControl ItemsSource="{Binding DataList}" AlternationCount="2"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid x:Name="FooBar" Margin="0,0,0,10"> </Grid> <DataTemplate.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="Blue" TargetName="FooBar"/> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="Red" TargetName="FooBar"/> </Trigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
Tim eeckhaut
source share