Search code examples
windows-phone-8textblock

update text of textblock every a half of second in windows phone 8


I want to random a number of my array. Then I show it in a textblock. I want to do it every second. How to update my textblock every second ?. Please to help me.


Solution

  • Create a dispatcher timer and for every ticks update your textbock.

    number = 0
    dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
    dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
    dispatcherTimer.Interval = new TimeSpan(0,0,1);
    dispatcherTimer.Start();
    
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        //if you use binding and mvvm
        this.Text = number.tostring();
        //if you don't use binding
        yourTextblock.Text = number.toString();
        number ++;
     }