I have a Xamarin.Forms application which calls the backend. The backend gives a list of items. These items all have a type and a description. Based on the type, I need to decide what view element I need to create (entry, label, picker, checkbox etc..). Also the description should probably be a label, each view has it's own description.
How can I achieve this? I really have a hard time figuring this out..
Example: the backend gives a list with two objects. First object has phonenumer has a type, second element has a boolean as a type. The firstone should just create an entry and the second one should create a picker. Both rows/views should have a description, that could be just a label.
You could use a Bindable Layout (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/bindable-layouts) with a DataTemplateSelector (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/selector) that provides the according DataTemplate depending on the Type of the object you receive.
On the XAML for each DataTemplate you can do the bindings (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-binding-basics)
This way you don't have to code anything in code-behind nor loop over anything, because the Bindable Layout will do it for you and decide what to show depending on what object it received.