c# - 使用带有 C# 的 XAML 为 Windows Phone 8 应用程序设置计时器

标签 c# windows xaml windows-phone-8

我正在开发 Windows Phone 8 游戏应用程序。

我需要在我的应用中添加倒计时功能。

就像应用程序启动时一样。定时器值显示 60,59,58....0

当到达 0 时显示消息“超时”。

我在 Google 上搜索过,但我不知道。 [可能是我没有以正确的方式搜索的错误]

我尝试使用以下代码显示日期和时钟值,如 [3/12/2014 6:22:10 PM]

C#代码

 public SensorTwo()
    {
        InitializeComponent();
        DispatcherTimer newTimer = new DispatcherTimer();
        newTimer.Interval = TimeSpan.FromSeconds(1);
        newTimer.Tick += OnTimerTick;
        newTimer.Start();
    }

 void OnTimerTick(Object sender, EventArgs args)
    {
        clock.Text = DateTime.Now.ToString();
    }

XAML 代码

<TextBlock Foreground="Red" FontSize="22"  Name="clock" Width="350" Height="50" HorizontalAlignment="Center" VerticalAlignment="Bottom"></TextBlock>

任何人帮助或指导我完成此功能......

最佳答案

//make global declaration of a counter variable 


 int counter =60;    
    void OnTimerTick(Object sender, EventArgs args)
       {       
         counter --;
         if(counter<0)
         {
          newTimer.Stop();
          counter=60;
         }
        else
         {
          clock.Text =counter.ToString();
         }
       }

关于c# - 使用带有 C# 的 XAML 为 Windows Phone 8 应用程序设置计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22352346/

相关文章:

C# ASP :ListBox hide vertical scrollbar

c# - 如何枚举所有可用的无线网络并将它们显示在列表框中?

node.js - Node 在 Windows 10 上找不到 webpack 模块

c# - 如何在触发器中设置属性 (WPF)

C# picturebox 绘制速度

c# - 从使用 Task.WhenAll() 等待的任务分配时避免检查条件两次

c++ - 为什么 va_start 会失败?

xaml - Xamarin 在 Xaml 中形成 OnPlatform

c# - 屏幕较小时增大字体大小

c# - 反转多维数组中元素的顺序