.NET MAUI DataGrid Validation Command
The .NET MAUI DataGrid control provides a validation command that has an entry point for validating cells content. The execution parameter is of type ValidateCellContext
and exposes the following properties:
-
CellInfo
—Gets the cell information associated with the operation. -
Errors
—Gets or sets the errors (if any) that occurred during the validation.
Example
Here is an example how the DataGrid ValidateCell
command works:
1. Create a Data
class (the business object) that inherits from the INotifyDataErrorInfo
and INotifyPropertyChanged
interfaces. For demonstration purposes, the example will do the validation through the INotifyDataErrorInfo
interface.
2. Create a ViewModel
with a collection of Data
objects:
3. Handle the CellTap
action as a Command
. First, create a class that inherits from the DataGridCommand
and set its Id
property. You will also need to override the CanExecute
and Execute
methods as demonstrated in the example below:
4. Set the BindingContext
to be the ViewModel
and add this command to the Commands
collection of the RadDataGrid
instance:
5. Define the DataGrid in XAML:
6. Use the telerik
namespace: