如何在提醒应用程序中启动计时器

时间:2014-06-05 07:02:06

标签: c# xaml windows-phone-7 windows-phone-8 timer

enter image description here

我正在处理我需要启动计时器的提醒应用程序,以便在计时器结束后它会让我想起我设置的事件。

在图像中,我已经包围了计时器。

        DispatcherTimer timer = new DispatcherTimer();
    timer.Interval=TimeSpan.


    private int Time;
    DispatcherTimer timer;
    private void TextBlock_Loaded(object sender, RoutedEventArgs e)
    {

    }

    void timer_Tick(object sender, EventArgs e)
    {
        if (Time > 0)
        {
            Time--;
            timer.Interval = TimeSpan.FromSeconds(1);
            Debug.WriteLine("  " + Time + "  \n");
        }
    }

    private void TextBox_Loaded(object sender, RoutedEventArgs e)
    {
        Time = ((sender as FrameworkElement).DataContext as PersonalModel).RemainingHours;
        timer = new DispatcherTimer();
        timer.Start();
        timer.Tick -= timer_Tick;
        timer.Tick += timer_Tick;
    }

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        ((sender as FrameworkElement)
    }

1 个答案:

答案 0 :(得分:1)

按照this教程了解如何在Windows Phone 8中设置提醒和提醒警报

以下是在Windows Phone 8中设置提醒的代码。

Reminder reminder = new Reminder(name);
reminder.Title = titleTextBox.Text;
reminder.Content = contentTextBox.Text;
reminder.BeginTime = beginTime; // it is the time when remider will start reminding(e.g remind me after 8 days and 2 AM hours you will set it DateTime.Now.Date.AddDays(8).AddHours(2)
reminder.ExpirationTime = expirationTime;
reminder.RecurrenceType = recurrence;
reminder.NavigationUri = navigationUri;

// Register the reminder with the system.
ScheduledActionService.Add(reminder);