Hi all,
I am really struggling with Xamarin Forms specifically the ListView, all was working about a month ago, now its not, there is so many issues, I fix one then another appears, First I would like a proper full example of an ObservableCollection/ListView where the list is properly refreshed, I see so many examples all slightly different what is best practice please someone show me an example.
Here is all the different ways I am seeing.
I have seen the use of Device.BeginInvokeOnMainThread used to wrap round the updating code I get it push the updates on the UI thread, is it really required because in my testing the code crashes just as much with or without it?
lstJob.BeginRefresh () and lstJob.EndRefresh () are these required?, back in the day you did this stuff in vb to batch all your UI updates into a single update rather than loads of little incremental updates.
Setting item source to null before repopulation e.g. lstJob.ItemsSource = null then lstJob.ItemsSource = jobList.
Do you set the DataTemplate once or every time to refresh e.g. lstJob.ItemTemplate = new DataTemplate (typeof (jobCell))?
I am getting untrappable errors with the very latest stable Xamarin.Forms 2.5.0.121934, app just disappears from the screen on both devices and simulators, one pretty significant issue is if you have a ViewCell and I am using AbsoluteLayout.Children.Add and add a label that has Text = null this totally closes the app with an untrappable error, ok I should make sure that everything is initialised but I would expect a trappable error that I can look at. so for example
protected override void OnBindingContextChanged () {
base.OnBindingContextChanged ();
if (BindingContext == null) {
return;
}
var absoluteLayout = new AbsoluteLayout {
};
tblJobs c = (tblJobs)BindingContext;
var netAmount = new Label {
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.End,
FontSize = Core.Instance.CellTextFontSize + Core.Instance.TextSize,
FontAttributes = FontAttributes.Bold,
TextColor = Color.Black,
};
absoluteLayout.Children.Add (netAmount, new Rectangle (1,1,100,100));
View = absoluteLayout;
}
Will produce a hard crash on my devices and simulators, just throwing in netAmount.Text = ""; solves some of those issues, this should be trappable.
Other errors that are trappable are things like when I am refreshing the ListView I get this error every now an again.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Any clarification on these would be great.
Thanks
Alex