Floating FB popout byF5debug

101 How to on Windows Phone – How to #57 – Programmatically Create Reminders in Windows Phone

 

In this article we are going to see how to Programmatically create Reminders from your application in Windows Phone application. In our previous article we have seen how to create an alarm from the application programmatically by assigning some of the properties that are required. With reminders we get the flexibility to customize by providing a specific relative navigation URI pointing to the page in the application where we can pass some query strings to act accordingly to understand what the user is trying to do with the reminder. Basically when the reminder is displayed to the end user there are possibilities that the user taps on it to accept the reminder or cancels to do some other step. Say if the user clicks on the reminder and we need to show a page telling the user to do some event which can be done by providing a URI of the application page. There is a restriction that we can use only a maximum of 50 reminders at a time in a application.     [more]

Let us see the steps on how to achieve this task in our Windows Phone application development. Open Visual Studio 2012 IDE and create a new Windows Phone project with a valid project name as shown in the screen below. 

image

Clicking on OK will create the project and the solution with the list of default files and folders that are required to run the application. It will take some time to create these files based on your system configuration, so once everything is ready we can see the Visual Studio IDE with the project as shown in the screen below.

image

Now let us add some controls which are basically required to create an reminder programmatically and show a message once the reminder is created. Let us make it more program oriented, but in real time we can control it based on the inputs from the users as shown in the screen below.

XAML Code:

[code:c#]

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="F5debug How to Series" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Reminders" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Create Reminder" Height="72" HorizontalAlignment="Left" Margin="9,6,0,0" Name="button1" VerticalAlignment="Top" Width="441" />
            <TextBlock Height="277" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="29,108,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="407" />
        </Grid>

[/code]

image

 

Now in the code behind let us add some code in the button click event of the Create Reminder button which basically creates an instance of the Reminder class and assign some dummy values which creates an reminder as shown in the code below.

C# Code:

[code:c#]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using F5debugHowto57.Resources;
using Microsoft.Phone.Scheduler;

namespace F5debugHowto57
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Reminder reminder = new Reminder("F5debug Reminder");
            reminder.Title = "Remind";
            reminder.Content = "This is test";
            reminder.RecurrenceType = RecurrenceInterval.Daily;

            //Date and time need to be specified
            //reminder.BeginTime = DateTime.Now;
            //reminder.ExpirationTime = DateTime.Now;

            string struri = "?param=Reminder App Passed";
            Uri navigationUri = new Uri("/ReminderAppPage.xaml" + struri, UriKind.Relative);
            reminder.NavigationUri = navigationUri;

            ScheduledActionService.Add(reminder);
        }

    }
}

[/code]

In this above code we can see the time and date part is commented, you can get the input from the end user by using any date time selection tool. Also the URI and the parameters which points are dummy pages so that you can specify the appropriate pages which gives the end user a feel of what he has setup as reminder. Also in the above code we have some properties which are to be considered before we write our requirement on top of the reminder properties. Some of the main properties are as follows

  • Name – Unique Name for the Reminder
  • Title – This is default name, and we cannot manually set this property
  • Content – This property is to set some content for the reminder.
  • Begin Time – Beginning of the Reminder
  • Expiration Time – Expiration time of the Reminder
  • Recurrence Type – Recurrence type of the Reminder
  • Navigation URI – On clicking of the application will navigate the user to the new page.

Now we are done with our configuration, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.

image

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter