Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Odd ListView - PushModalAsync/PopModalAsync behaviour?

$
0
0

This is mind boggling...

I have a listview with some code attached to listView.ItemSeleected handler:

listView.ItemSelected += async (sender, e) =>
{

            var option = (Option)e.SelectedItem;

            await Navigation.PushModalAsync(new ScoreOptionView(decision, option));


        };

This results in a new View being Pushed and displaying correctly.
In this view, I make some changes to a form and save to local database via the viewModel

_service.SaveScoredFactors(arg.decision.Id,arg.option.Id,arg.FactorScoreList); // save to db
await Navigation.PopModalAsync(true); // return to listview

So far so good, I am returned back to the listView page.

When I selected the next item in the listview, I again call PushModalAsync, and end up on my form page.
I hit the save button, database save happens in the ViewModel... and then something odd happens and I can't figure out why:

It appears the save code is being called twice automatically:

_service.SaveScoredFactors(arg.decision.Id,arg.option.Id,arg.FactorScoreList); // this gets called twice - for each item in the listview...
await Navigation.PopModalAsync(true); // this get's called twice, the first time it doesn't throw an error, the second time it throws:

System.ArgumentOutOfRangeException: Argument is out of range.

So - Any ideas why clicking the second item in the listview is calling the code twice?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>