How to set the AlternatingRowStyle to TextBox which is directly loaded into GridTemplateColumn in UWP DataGrid?
SfDataGrid.AlternatingRowStyle property helps you to apply styles for the alternate rows in SfDataGrid. When you set the SfDataGrid.AlternatingRowStyle, the style is not applied to TextBox that is directly loaded into GridTemplateColumn as displayed in the following screenshot.
You can overcome this by setting the TextBox Background as Transparent that is loaded in GridTemplateColumn.
The following code example explains the SfDataGrid is defined with AlternatingRowStyle and GridTemplateColumn is defined with TextBox.
XML
<!--Need to add this code snippet in Resources Define the style with Key--> <Style x:Key="AlternateRowStyle" TargetType="syncfusion:VirtualizingCellsControl"> <Setter Property="Background" Value = "LightGray " /> </Style> <syncfusion:SfDataGrid Name="SfdataGrid" AlternatingRowStyle="{StaticResource AlternateRowStyle}" AllowDraggingColumns="True" AllowEditing="True" ColumnSizer="Star" AutoGenerateColumns="False" ItemsSource="{Binding Employee}" NavigationMode="cell"> <syncfusion:SfDataGrid.Columns> <syncfusion:GridTemplateColumn HeaderText="Employee Name" MappingName="Name" > <syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <TextBox Background="Transparent" Text="{Binding Name}" /> </DataTemplate> </syncfusion:GridTemplateColumn.CellTemplate> </syncfusion:GridTemplateColumn> </syncfusion:SfDataGrid.Columns> </syncfusion:SfDataGrid>
The following screenshot displays the output of SfDataGrid with AlternatingRowStyle. Here, the TextBox is loaded to the Employee name column.
Sample Links,
Conclusion
I hope you enjoyed learning about how to set the AlternatingRowStyle to TextBox which is directly loaded into GridTemplateColumn.
You can refer to our
UWP DataGrid feature tour page to know about its other groundbreaking
feature representations and documentation, and
how to quickly get started for configuration specifications. You can also
explore our UWP
DataGrid example
to
understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!