Articles in this section
Category / Section

How to render DataForm using FSharp application in Xamarin.Forms?

1 min read

This article explains how to render DataForm using FSharp application in Xamarin.Forms.

 

Define the properties in the model class.

 

   type ContactForm() =     
 
    member val Name = "John" with get,set
    member val Age= "20" with get,set
    member val Address = "" with get,set
    member val Email = "" with get,set 

 

In the main page, load the DataForm content in the FSharp project.

 

    type DataFormFSharp() = 
    inherit ContentPage()
 
    let _ = base.LoadFromXaml(typeof<DataFormFSharp>)    
    let dataForm = base.FindByName<SfDataForm>("dataForm")       
 
 
    type App() = 
    inherit Application(MainPage = DataFormFSharp()) 

 

Bind the view model to the ContentPage, and include DataForm inside a StackLayout. This is a function that takes the model and returns a UI based on the model.

 

    <ContentPage.BindingContext>
        <local:ViewModel></local:ViewModel>
    </ContentPage.BindingContext>
    <ContentPage.Content>
        <StackLayout Orientation="Vertical"
                     HorizontalOptions="FillAndExpand"
                     VerticalOptions="FillAndExpand">
            <dataForm:SfDataForm x:Name="dataForm"
                             VerticalOptions ="FillAndExpand"
                              DataObject="{Binding ContactInformation}"
                              BackgroundColor="White"
            </dataForm:SfDataForm>
        </StackLayout>
    </ContentPage.Content>

 

Set the ContactForm model class in the view model class of the application.

 

type ViewModel() =     

    member val ContactInformation = ContactForm() with get, set
 
 

 

Sample Demo: DataFormFSharp

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied