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

Refresh ui from a loop in the viewmodel

$
0
0

I have a loop in my viewmodel which cycles through random dice rolls. It works fine updating the dice for the final numbers, but I really want the dice images to cycle along with the rolls so that the user can see every number. The problem is, the command doesn't return to the Ui until the final number is bound.

How can I refresh the Ui and show the bound images during the loop?

Here is the appropriate section of code:

RandomTimes = new Random();
RandomDiceRoll = new Random();
iteration = RandomTimes.Next(25, 40);

        for (int j = 0; j < iteration; j++)
        {

            for (int i = 0; i < Dice.Length; i++)
                Dice[i] = RandomDiceRoll.Next(1, 6 + 1);

            if (!Die1Saved)
            {
                Die1 = Dice[0];
                DiePic1 = DiceImages[Dice[0]];

            }
            if (!Die2Saved)
            {
                Die2 = Dice[1];
                DiePic2 = DiceImages[Dice[1]];

            }
            if (!Die3Saved)
            {
                Die3 = Dice[2];
                DiePic3 = DiceImages[Dice[2]];

            }
            if (!Die4Saved)
            {
                Die4 = Dice[3];
                DiePic4 = DiceImages[Dice[3]];

            }
            if (!Die5Saved)
            {
                Die5 = Dice[4];
                DiePic5 = DiceImages[Dice[4]];

            }

//REFRESH THE UI SOMEHOW!!!!
}


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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