Articles in this section
Category / Section

How to show the selection of row/cell when setting the background for SfDataGrid GridCell in UWP ?

1 min read

Problem

Row/Cell selection border is behind the GridCell content. So when you apply the background for GridCell, the selection is not displayed in UI.

The following code example shows you how to set the GridCell style.

XAML

<!--Need to add this code snippet in Resources Define the style with Key-->
<Style x:Key="ApplyCellStyle" TargetType="Syncfusion:GridCell">
        <Setter Property="Background">
               <Setter.Value>
                    <SolidColorBrush Color="Blue" />
                </Setter.Value>
         </Setter>          
</Style>       
<Syncfusion:SfDataGrid x:Name="datagrid" 
                                       ColumnSizer="Star" 
                                       SelectionUnit="Row"  
                                       AllowSelectionOnPointerPressed="True"  
                                       RowSelectionBrush="Red"  
                                       CellStyle="{StaticResource ApplyCellStyle}"  
                                       ItemsSource="{Binding GDCSource}"  
                                       SelectionMode="Single" 
                                       >
</Syncfusion:SfDataGrid>

In the following screenshot, the selection is set in the 5th row, but it is not displayed in View with the selection border in the Cell Content presenter.

Row selection in Silver light DataGrid

Figure 1: 5th Row Selection

Solution

You can overcome this problem by reducing the Opacity for the brush that you set to the GridCell background. The following code example shows you how to set the Opacity to GridCell.

XAML

<!--Need to add this code snippet in Resources Define the style with Key-->
<Style x:Key="ApplyCellStyle" TargetType="Syncfusion:GridCell">
        <Setter Property="Background">
               <Setter.Value>
                    <SolidColorBrush Color="Blue" Opacity="0.5"/>
                </Setter.Value>
         </Setter>          
</Style>       
<Syncfusion:SfDataGrid x:Name="datagrid" 
                                       ColumnSizer="Star" 
                                       SelectionUnit="Row"  
                                       AllowSelectionOnPointerPressed="True"  
                                       RowSelectionBrush="Red"  
                                       CellStyle="{StaticResource ApplyCellStyle}"  
                                       ItemsSource="{Binding GDCSource}"  
                                       SelectionMode="Single" 
                                       >
</Syncfusion:SfDataGrid>

The following screenshot shows you the selection of row after applying background for GridCell also.

Row selection after applying background in in Silver light DataGrid

Figure 2: selection of row after applying background

 

Sample Links:

WPF

WRT

SilverLight

UWP

Conclusion

I hope you enjoyed learning about how to show the selection of row/cell when setting the background for SfDataGrid GridCell in UWP.

You can refer to our UWP SfDataGrid 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 SfDataGrid  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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied