Articles in this section
Category / Section

How to set the minimum and maximum date for the date editor in .NET MAUI DataForm (SfDataForm)?

4 mins read

The Syncfusion® .NET MAUI DataForm allows you to control the date range a user can select by setting the minimum and maximum dates for date editors. This can be done using the MinimumDisplayDate and MaximumDisplayDate properties.

Register the editors using the RegisterEditor method and change the minimum and maximum dates using the GenerateDataFormItem event by setting the MinimumDisplayDate and MaximumDisplayDate properties in the event.

 
public class DataFormBehavior : Behavior<SfDataForm>
{
    protected override void OnAttachedTo(SfDataForm dataForm)
    {
        base.OnAttachedTo(dataForm);
        dataForm.RegisterEditor("AppointmentDate", DataFormEditorType.Date);
        dataForm.RegisterEditor("AppointmentTime", DataFormEditorType.Time);
        dataForm.GenerateDataFormItem += OnGenerateDataItem;
    }
 
    private void OnGenerateDataItem(object sender, GenerateDataFormItemEventArgs e)
    {
        if (e.DataFormItem != null && e.DataFormItem is DataFormDateItem dateItem)
        {
            dateItem.MinimumDisplayDate = new DateTime(2022, 12, 05);
            dateItem.MaximumDisplayDate = new DateTime(2022, 12, 25);
        }
    }
}

C#

Bind the DataFormModel property to the DataObject property of the SfDataForm.

XAML

 
<dataForm:SfDataForm x:Name="dataForm"
                     DataObject="{Binding DataFormModel}">
            <dataForm:SfDataForm.BindingContext>
                <local:DataFormViewModel/>
            </dataForm:SfDataForm.BindingContext>
            <dataForm:SfDataForm.Behaviors>
                <local:DataFormBehavior/>
            </dataForm:SfDataForm.Behaviors>
</dataForm:SfDataForm>

Download the complete sample on GitHub

Output:

Minimum and maximum date of the date editor using Syncfusion .NET MAUI DataForm

Conclusion

I hope you enjoyed learning how to set the minimum and maximum date for the date editor in .NET MAUI DataForm (SfDataForm).

Refer to our .NET MAUI DataForm feature tour page for its other groundbreaking feature representations. You can also explore our .NET MAUI DataForm documentation to understand how to present and manipulate data.

 

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataForm and other .NET MAUI components.

 

Please let us know in the following comments section if you have any queries or require clarification. Contact us through our support forums, Direct-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  to leave a comment
Access denied
Access denied