Is it possible to change the background color of the view cell if the information in the view cell is not complete.
In the image connected the first item in the ListView is filled in completely and I want to display the background color white. The second item in the list has incomplete information and I want to display that to the user with a red or yellow background so they know that item has unfilled data.
This app is a data collection app for cruising timber lands.
Set binding to the item's BackgroundColor. Then detect the change of these binding properties to set value to the backgroundColor.
Check the code:
Model class
public class Model_4 : INotifyPropertyChanged { public Model_4() { _Color = Color.White; } ... private string description; public string Description { get { return description; } set { if (description != value) { description = value; NotifyPropertyChanged(); if (string.IsNullOrEmpty(Description)) { _Color = Color.Red; } else { _Color = Color.White; } } } } private Color _color; public Color _Color { get { return _color; } set { if (_color != value) { _color = value; NotifyPropertyChanged(); } } } protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public event PropertyChangedEventHandler PropertyChanged; }
Page.xaml
<ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout BackgroundColor="{Binding _Color}"> <Label Text="{Binding Content}" VerticalOptions="CenterAndExpand"/> <Entry Text="{Binding Description}" VerticalOptions="CenterAndExpand" /> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate>
Answers
Set binding to the item's BackgroundColor. Then detect the change of these binding properties to set value to the backgroundColor.
Check the code:
Model class
Page.xaml