在Windows Phone 8中每隔半秒更新一次文本块的文本

时间:2014-01-12 16:35:03

标签: windows-phone-8 textblock

我想随机抽取一些我的数组。然后我在一个文本块中显示它。我想每秒都这样做。如何每秒更新我的文本块?请帮帮我。

2 个答案:

答案 0 :(得分:1)

创建一个调度程序计时器,并为每个刻度更新您的文本块。

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 ++;
 }

答案 1 :(得分:0)

创建调度程序计时器和每半秒更新文本框

    int number=0;
    private DispatcherTimer _timer;
    public sample()
    {
        InitializeComponent();
        _timer = new DispatcherTimer();
        _timer.Interval = new TimeSpan(0, 0, 0,0,500);
        _timer.Tick += _timer_Tick;
        _timer.Start();
    }
    void _timer_Tick(object sender, EventArgs e)
    {
      number++;
      yourTextblock.Text = number.toString();
    }