I would like to have a datagrid with alternating rows. I have tried to use the example and can't get it to work.
Datagrid in xaml:
<Grid:SfDataGrid x:Name="gridLDQ" AutoGenerateColumns="False"
HeaderStyle="{StaticResource headerStyle}" AllowGrouping="False" AllowResizingColumns="False" AutoExpandGroups="False" DetailsViewPadding="0"
NavigationMode="Row" AllowSorting="False" BorderThickness="0" CurrentCellBorderThickness="0" CurrentCellBorderBrush="#00FFFFFF"
RowStyleSelector="{StaticResource rowStyleSelector}" CellStyle="{StaticResource cellStyle}">
<Grid:SfDataGrid.Columns>
<Grid:GridTextColumn MappingName="Reqnum" HeaderText="Req #" Width="80"/>
<Grid:GridTextColumn MappingName="Ternum" HeaderText="Ter #" Width="60"/>
<Grid:GridTextColumn MappingName="Customer" HeaderText="Customer" Width="280"/>
<Grid:GridTextColumn MappingName="BU" HeaderText="BU" Width="60"/>
<Grid:GridTextColumn MappingName="ReqDesc" HeaderText="Description" Width="280"/>
</Grid:SfDataGrid.Columns>
</Grid:SfDataGrid>
Added this in page.resources
<local:CustomRowStyleSelector x:Key="rowStyleSelector" />
Added the class (in vb)
Public Class CustomRowStyleSelector
Inherits StyleSelector
Protected Overrides Function SelectStyleCore(item As Object, container As DependencyObject) As Style
Return MyBase.SelectStyleCore(item, container)
If item.RowIndex Mod 2 = 0 Then
Return App.Current.Resources("altrowStyle")
Else
Return App.Current.Resources("rowStyle")
End If
End Function
End Class
My styles in app.xaml
<Style x:Key="rowStyle" TargetType="Grid:VirtualizingCellsControl">
<Setter Property="Background" Value="#7380a605"/>
<Setter Property="Padding" Value="0"/>
</Style>
<Style x:Key="altrowStyle" TargetType="Grid:VirtualizingCellsControl">
<Setter Property="Background" Value="#3A80a605"/>
<Setter Property="Padding" Value="0"/>
</Style>
<Style x:Key="cellStyle" TargetType="Grid:GridCell">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="#FFEFEFEF"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="headerStyle" TargetType="Grid:GridHeaderCellControl">
<Setter Property="Foreground" Value="#FF80a605"/>
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
It doesn't go into the function to change the row styles. Is it because I do not set the itemssource in xaml, instead later in code?