Is it possible to attach a style or define a property in the WPF System.Windows.Controls.Grid
in order to alternate the color of the rows(or columns)?
I need that User be able to place a grid placeholder (something similar to CrystalReports)... It can parameter the grid, but the grid (in View) will not contain any data.
The only way I can think of doing this is by hand using a Rectangle
either declared before the row contents or with it's Z order set to push it to the back:
<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>
You might be able to use bindings to pass the row number to a converter to return the correct colour rather than hard coding like I have here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With