Forum General

Bind ListView to multiple types and objects

tvaltval Member ✭✭
edited May 2019 in General

Is it possible to bind a List View with Grouping to multiple property types? For example I have a list of application settings, and from those I create a list:
List settingsList = Settings.ToBindableList();
From this settings list, I would like the ListView to show a View Cell with a StackLayout and a Label:

    <StackLayout Orientation="Horizontal" Padding="10,5,5,10" BackgroundColor="White">
    <Label Text="{Binding DisplayName}" HorizontalOptions="StartAndExpand"/>
    <Label Text="{Binding Value}" HorizontalOptions="End" TextColor="Blue"/>

This works in most cases if it is a string or int type, but is it possible to create multiple DataTemplates in a single List View that shows the following
Width 2
Company MyCompany, Inc.
MyColor Blue
Name John
State California

public class BindableSetting
    public string DisplayName {get;set;}
    public object Value {get;set;}

public class Settings
    public int Width {get;set;}
    public string Company {get;set;}
    public Color MyColor{get;set;}
    public Person Person {get;set;}

    public List<BindableSettings>ToBindableList()
    //Bunch of reflection to get all the settings and return it as a list

public class Person
    public string Name {get;set;}
    public StateEnum State{get;set;}    


Sign In or Register to comment.