How to render DataForm using FSharp application in Xamarin.Forms?
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