Alternate grid row colors?

Is it possible to attach a style or define a property in WPF System.Windows.Controls.Grid to alternate the color of rows (or columns)?

I need the User to be able to place the grid placeholder (something similar to CrystalReports) ... He can parameterize the grid, but the grid (in the view) will not contain any data.

+4
source share
1 answer

The only way I can do this is to manually use the Rectangle declared before or with the contents of the string to set it in the opposite direction:

 <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> 

Perhaps you can use the bindings to transfer the line number to the converter in order to return the correct color, rather than hard coding, as here.

+4
source

Source: https://habr.com/ru/post/1400550/


All Articles