How to Set Swipe Offset Based on its Content Size in .NET MAUI DataGrid?
In this article, we will show you how to set the swipe offset based on its content size in .NET MAUI DataGrid.
xaml
The code below demonstrates how to set the swipe offset based on its content size in DataGrid.
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding Employees}"
ColumnWidthMode="Auto"
AutoGenerateColumnsMode="None"
GridLinesVisibility="Both"
SwipeOffsetMode="Auto"
HeaderGridLinesVisibility="Both"
AllowSwiping="True">
<syncfusion:SfDataGrid.LeftSwipeTemplate>
<DataTemplate>
<Grid BackgroundColor="Blue"
Padding="9">
<Label Text="EDIT"
HorizontalTextAlignment="End"
TextColor="#FFFFFF"
VerticalTextAlignment="Center"
LineBreakMode="NoWrap"
BackgroundColor="Transparent" />
</Grid>
</DataTemplate>
</syncfusion:SfDataGrid.LeftSwipeTemplate>
<syncfusion:SfDataGrid.RightSwipeTemplate>
<DataTemplate>
<Grid BackgroundColor="Red"
Padding="9">
<Label FontSize="15"
HorizontalTextAlignment="Center"
Text="Delete"
TextColor="White"
VerticalTextAlignment="Center"
LineBreakMode="NoWrap" />
</Grid>
</DataTemplate>
</syncfusion:SfDataGrid.RightSwipeTemplate>
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
Note
The value of the SfDataGrid.MaxSwipeOffset property will not be considered when the SfDataGrid.SwipeOffsetMode is set to SwipeOffsetMode.Auto.
Output
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to set the swipe offset based on its content size in .NET MAUI DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations and documentation to understand how to present and manipulate data.
For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!