0
votes

In Xamarin Forms, I'm working on a PCL application where I want to change the background color of a listview item based on datacolumn value. For the moment I'm working in XAML.

<ContentPage.Content>
<StackLayout Spacing="10" x:Name="layout">
  <ListView  x:Name="listView" HasUnevenRows="True" RowHeight="200" >
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell Tapped="OnItemTapped">
          <StackLayout BackgroundColor="#eee"
          Orientation="Vertical" VerticalOptions="FillAndExpand">
            <StackLayout Orientation="Horizontal">
              <Label Text="{Binding Ingredient}" 
              TextColor="#f35e20" FontSize="Medium" FontAttributes="Bold" />
            </StackLayout>
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</StackLayout>

The list is filled with values (Dog, Cat, Bird) and in a datatable I have these values as columns which are datatype boolean. According to this boolean values I want to change the background of each listviewitem. So Dog corresponding to column Dog... Is there some way to do this with a Binding? Thanks in advance!

1

1 Answers

0
votes

Have you tried another color like: BackgroundColor="#00FF00" and horizontal options and vertical options FillAndExpand?