I was wondering if someone could point me in the right direction to the following:
I have a StackLayout that I'm populating child views with as I iterate through my ObservableCollection. I've bound values from each object in the ObservableCollection to labels that are populated. The initial population is fine but updating values in the collection isn't updating in the child views UI.
The following is the code:
My ObservableCollection in my Viewmodel
private ObservableCollection<DataModel> data;
public ObservableCollection<DataModel> Data
{
set
{
if (data != value)
{
data = value;
OnPropertyChanged("Data");
}
}
get
{
return data;
}
}
}
The iteration through the ObservableCollection to populate the child layouts
void PopulateData()
{
vm.Data.ForEach((obj) => MiddleLayout.Children.Add(new BoxTab(obj)));
}
Setting the bindings for the two labels in the box tab
public partial class BoxTab : ContentView
{
public SheetsTab(DataModel data)
{
InitializeComponent();
Name.SetBinding(Label.TextProperty, "Name");
Name.BindingContext = new { Name = data.Name };
TransactionCount.SetBinding(Label.TextProperty, "Count");
TransactionCount.BindingContext = new { Count = data.Count };
}
}
I then want to edit the data in the collection like:
public void ReloadData()
{
int count = 10
var item = Data.FirstOrDefault(i => i.Name == "Test");
if (item != null)
{
item.Count = count;
}
}
What's the correct way to raise OnPropertyChanged so the individual BoxTab that item.Counts value changed updates its view. I've tried various ways like:
OnPropertyChanged("SheetTabData["+ i +"]");
OnPropertyChanged("SheetTabData[" + i + "].Count");
But I must be missing something. Any help would great, Thanks!!