I want to have a page that has a Table View with just Entry Cells. It's an "Update Details" feature inside the app. I want to make it more user friendly as in I separate the entry cells into two parts and fill the top ones with the data that's already in the object, and what's null I put a placeholder instead.
So far I just have ifs and elses everywhere. I check every single attribute and see if it's null. If not, I put its value inside the entry cell. If it is, I add a placeholder instead.
if (car.Make != null)
Weknow.Add(new EntryCell {Label = "Make", Text = car.Make});
else
Wedont.Add(new EntryCell {Label = "Make", Placeholder = "Eg. Ford"});
if (car.Manufacturer != null)
Weknow.Add(new EntryCell {Label = "Manufacturer", Text = car.Manufacturer});
else
Wedont.Add(new EntryCell {Label = "Manufacturer", Placeholder = "Eg. Ford Werke AG"});
if (car.Plant != null)
Weknow.Add(new EntryCell {Label = "Plant", Text = car.Plant});
else
Wedont.Add(new EntryCell {Label = "Plant", Placeholder = "Eg. Koeln-Niehl"});
if (car.ModelYear != null)
Weknow.Add(new EntryCell {Label = "ModelYear", Text = car.ModelYear});
else
Wedont.Add(new EntryCell {Label = "ModelYear", Placeholder = "Eg. 2010"});
if (car.SequentialNumber != null)
Weknow.Add(new EntryCell {Label = "SequentialNumber", Text = car.SequentialNumber});
else
Wedont.Add(new EntryCell {Label = "SequentialNumber", Placeholder = ""});
if (car.Model != null)
Weknow.Add(new EntryCell {Label = "Model", Text = car.Model});
else
Wedont.Add(new EntryCell {Label = "Model", Placeholder = "Eg. Focus"});
Weknow is the table section containing the Entry cells that have values, and Wedont is the section with the ones that are null, and have a placeholder.
The end result is this: https://i.stack.imgur.com/EbTVB.jpg
Everything works, but I'm wondering if there is any simpler way to go through an object and see if properties are null and if they are, then there should be a placeholder instead. I was thinking of having a Binding Context but I wanted to do all of this in code rather than XAML. But if it can be done that way, I could try.
Thanks!