How to Use Visible Property With Binding in .NET MAUI DataGrid?
In this article, we will show you how to use Visible property using binding in .NET MAUI DataGrid.
xaml
The code below demonstrates how to use Visible property using binding in DataGrid.
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfDataGrid x:Name="dataGrid"
Margin="10"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
ColumnWidthMode="Auto"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding Employees}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
Visible="{Binding IsColumnVisible}"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
C#
EmployeeViewModel.cs
private bool _isColumnVisible = false;
public bool IsColumnVisible
{
get => _isColumnVisible;
set
{
if (_isColumnVisible != value)
{
_isColumnVisible = value;
NotifyPropertyChanged(nameof(IsColumnVisible));
}
}
}
Take a moment to explore this documentation, where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).
Conclusion
I hope you enjoyed learning on how to use visible property with binding in .NET MAUI DataGrid.
You can refer to our .NET MAUI 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 .NET MAUI 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!