|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Liquid Glass Effect for .NET MAUI DataGrid | Syncfusion® |
| 4 | +description: Learn how to enable and customize the Liquid Glass Effect in the Syncfusion® .NET MAUI DataGrid (SfDataGrid) control. |
| 5 | +platform: MAUI |
| 6 | +control: SfDataGrid |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Liquid Glass Effect in .NET MAUI DataGrid (SfDataGrid) |
| 11 | + |
| 12 | +The Liquid Glass Effect introduces a modern, translucent design with adaptive color tinting and light refraction, creating a sleek, glass like user experience that remains clear and accessible. This section explains how to enable and customize the effect in the Syncfusion® .NET MAUI DataGrid (SfDataGrid) control. |
| 13 | + |
| 14 | +## Apply liquid glass effect |
| 15 | + |
| 16 | +Follow these steps to enable and configure the Liquid Glass Effect in the DataGrid control: |
| 17 | + |
| 18 | +### Step 1: Wrap the control inside glass effect view |
| 19 | + |
| 20 | +To apply the Liquid Glass Effect to Syncfusion® .NET MAUI `SfDataGrid` control, wrap the control inside the `SfGlassEffectView` class. |
| 21 | + |
| 22 | +For more details, refer to the `Liquid Glass Getting Started documentation`. |
| 23 | + |
| 24 | +### Step 2: Enable the liquid glass effect on DataGrid |
| 25 | + |
| 26 | +Set the `EnableLiquidGlassEffect` property to `true` in the `SfDataGrid` control to apply the Liquid Glass Effect. When enabled, the effect is also applied to its dependent surfaces such as the row/column dragging view, tooltip, popups, context menu, and editor drop-downs (e.g., ComboBox/Picker) when their corresponding backgrounds are set to `Transparent` for a smooth and engaging user experience. |
| 27 | + |
| 28 | +### Step 3: Customize the background |
| 29 | + |
| 30 | +To achieve a glass like background in the DataGrid related surfaces such as ContextMenu, Tooltip, RowDragViewBackground, and ColumnDragViewBackground, set their `Background` to `Transparent`. The background will then be treated as a tinted color, ensuring a consistent glass effect across the control and its overlays. |
| 31 | + |
| 32 | +The following code snippet demonstrates how to apply the Liquid Glass Effect to the `SfDataGrid` control: |
| 33 | + |
| 34 | +{% tabs %} |
| 35 | +{% highlight xaml tabtitle="MainPage.xaml" hl_lines="14 16 20" %} |
| 36 | + |
| 37 | +<Grid> |
| 38 | + <Grid.Background> |
| 39 | + <LinearGradientBrush StartPoint="0,0" |
| 40 | + EndPoint="0,1"> |
| 41 | + <GradientStop Color="#0F4C75" |
| 42 | + Offset="0.0"/> |
| 43 | + <GradientStop Color="#3282B8" |
| 44 | + Offset="0.5"/> |
| 45 | + <GradientStop Color="#1B262C" |
| 46 | + Offset="1.0"/> |
| 47 | + </LinearGradientBrush> |
| 48 | + </Grid.Background> |
| 49 | + |
| 50 | + <core:SfGlassEffectView EffectType="Regular" |
| 51 | + CornerRadius="20"> |
| 52 | + <syncfusion:SfDataGrid x:Name="dataGrid" |
| 53 | + Background="Transparent" |
| 54 | + ItemsSource="{Binding OrderInfoCollection}" |
| 55 | + EnableLiquidGlassEffect="True"> |
| 56 | + <!-- Make specific surfaces transparent to reveal glass --> |
| 57 | + <syncfusion:SfDataGrid.DefaultStyle> |
| 58 | + <syncfusion:DataGridStyle RowDragViewBackgroundColor="Transparent" |
| 59 | + ColumnDragViewBackgroundColor="Transparent"/> |
| 60 | + </syncfusion:SfDataGrid.DefaultStyle> |
| 61 | + </syncfusion:SfDataGrid> |
| 62 | + </core:SfGlassEffectView> |
| 63 | +</Grid> |
| 64 | + |
| 65 | +{% endhighlight %} |
| 66 | +{% highlight c# tabtitle="MainPage.xaml.cs" hl_lines="21 22 23 24 25 30" %} |
| 67 | + |
| 68 | +using Syncfusion.Maui.Core; |
| 69 | +using Syncfusion.Maui.DataGrid; |
| 70 | + |
| 71 | +var gradientBrush = new LinearGradientBrush |
| 72 | +{ |
| 73 | + StartPoint = new Point(0, 0), |
| 74 | + EndPoint = new Point(0, 1), |
| 75 | + GradientStops = new GradientStopCollection |
| 76 | + { |
| 77 | + new GradientStop { Color = Color.FromArgb("#0F4C75"), Offset = 0.0f }, |
| 78 | + new GradientStop { Color = Color.FromArgb("#3282B8"), Offset = 0.5f }, |
| 79 | + new GradientStop { Color = Color.FromArgb("#1B262C"), Offset = 1.0f } |
| 80 | + } |
| 81 | +}; |
| 82 | + |
| 83 | +var grid = new Grid |
| 84 | +{ |
| 85 | + Background = gradientBrush |
| 86 | +}; |
| 87 | + |
| 88 | +var glassView = new SfGlassEffectsView |
| 89 | +{ |
| 90 | + CornerRadius = 20, |
| 91 | + EffectType = LiquidGlassEffectType.Regular |
| 92 | +}; |
| 93 | + |
| 94 | +var dataGrid = new SfDataGrid |
| 95 | +{ |
| 96 | + Background = Colors.Transparent, |
| 97 | + ItemsSource = viewModel.OrderInfoCollection, |
| 98 | + EnableLiquidGlassEffect = true |
| 99 | +}; |
| 100 | + |
| 101 | +// Make specific surfaces transparent to reveal glass |
| 102 | + |
| 103 | +dataGrid.DefaultStyle.RowDragViewBackgroundColor = Colors.Transparent; |
| 104 | +dataGrid.DefaultStyle.ColumnDragViewBackgroundColor = Colors.Transparent; |
| 105 | + |
| 106 | + |
| 107 | +glassView.Content = this.dataGrid; |
| 108 | +grid.Children.Add(glassView); |
| 109 | +this.Content = grid; |
| 110 | + |
| 111 | +{% endhighlight %} |
| 112 | +{% endtabs %} |
| 113 | + |
| 114 | +N> |
| 115 | +* Supported on `macOS 26 or higher` and `iOS 26 or higher`. |
| 116 | +* This feature is available only in `.NET 10.` |
0 commit comments