Bind an SfDataForm DataFormTimeItem in xaml

I'm looking to move some existing .NET MAUI XAML Content Page forms to SfDataForm.

I've mapped the control to an existing viewmodel and have set  the AutoGenerateItems to false;

Using the SfDataform how would I apply a Value Converter for a DataFormTimeItem in XAML? 

Using the .NET MAUI TimePicker it's quite simple as follows:

Time="{Binding ActivityTime, Mode=TwoWay, Converter={StaticResource TimeSpanToStringConverter}}"

How do I replicate this for the DataFormTimeItem in XAML (NOT code-behind)?

Regards,

Iain

1 Reply

VM Vidyalakshmi Mani Syncfusion Team January 17, 2025 01:42 PM UTC

Hi Iain,


Thank you for reaching out. When `AutoGenerateItems` is set to `false`, you can manually define the items in XAML, and the `FieldName` will map to the corresponding property in your model. The values for these items will be automatically updated based on the data object of the `SfDataForm`.


For example, you can set the value for the `DataFormTimeItem` in the model class as shown below:


       

<dataForm:SfDataForm  x:Name="dataForm"

                                            DataObject="{Binding ContactInfo}"

                                            AutoGenerateItems="False">

 

                <dataForm:SfDataForm.Items>

 

                            <dataForm:DataFormTimeItem FieldName="EventTime" />

 

                </dataForm:SfDataForm.Items>

 

</dataForm:SfDataForm>

 


Model class:

   

public class ContactInfo

{

        [DataType(DataType.Time)]

        [Display(Name = "Event Time")]

        public TimeSpan? EventTime { get; set; } = new TimeSpan(18, 30, 0);

}

 


We’ve also prepared a simple sample to demonstrate this. Please review the attached sample and let us know if you need any further assistance.


Regards,

Vidyalakshmi M.



Attachment: MAUIDataForm_d965a32f.zip

Loader.
Up arrow icon