Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 4) - Creating the To-Do Item Shell Tile, Saving a To-Do Item

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
9/10/2014 4:25:49 AM
Creating the To-Do Item Shell Tile

To create a shell tile, you must pass a StandardTileData instance to the static ShellTile.Create method. Because this is performed in several places in the sample, the code for creating the StandardTileData has been placed into a class called TodoTileDataCreator (see Listing 6). This class uses the to-do item’s due date to determine the numeric icon shown on the tile. If it exceeds 99 days, it is not shown. The tile has a foreground and a background image, and shows the description and due date of the to-do item.

LISTING 6. TodoTileDataCreator Class


public static class TodoTileDataCreator
{
    public static StandardTileData CreateTile(
        string todoItemDescription, DateTime dueDate)
    {
        /* The Count property of the tile data is set
         * to the number of days remaining.
         * It must be between 0 and 99 inclusively. */
        int daysUntilDue = 0;
        bool overdue = DateTime.Now > dueDate;
        if (!overdue)
        {
            int temp = (int)(DateTime.Now - dueDate).TotalDays;
            if (temp < 100)
            {
                daysUntilDue = temp;
            }
        }

        const string tilesDirectory = "/TodoList/Images/Tiles/";

        string backgroundUrl = overdue
                                    ? tilesDirectory + "Overdue.jpg"
                                    : tilesDirectory + "Ok.jpg";

        StandardTileData tileData = new StandardTileData
            {
                Title = todoItemDescription,
                BackgroundImage = new Uri(backgroundUrl, UriKind.Relative),
                Count = overdue ? 0 : daysUntilDue,

                BackTitle = dueDate.ToShortDateString(),
                BackContent = todoItemDescription,
                BackBackgroundImage = new Uri(
                    tilesDirectory + "Background.jpg", UriKind.Relative)
            };

        return tileData;
    }
}

Saving a To-Do Item

Saving an item involves instantiating a new item and sending it to the ITodoService to be stored in the database (see Listing 7).

If a shell tile is created for the to-do item, the NavigationUri of the tile is set to the TodoItemView page, and the Id of the TodoItem is placed in the query string of the URI, so that by tapping the tile, the user is brought back to the TodoItemView page, which allows editing or deletion of the to-do item.


Note

Calling ShellTile.Create immediately deactivates your app.


The final task of the SaveItem method is to navigate the user back to the TodoItemList page.

LISTING 7. TodoItemViewModel SaveItem Method


void SaveItem(bool createTile)
{
    if (string.IsNullOrWhiteSpace(todoDescription))
    {
        MessageService.ShowError("Please enter a description.",
                                    "Required Field Missing");
        return;
    }

    if (todoItem == null)
    {
        todoItem = new TodoItem();
    }

    todoItem.Description = todoDescription;
    todoItem.DueDate = todoDueDate;

    todoService.AddOrUpdateItem(todoItem);
    StandardTileData tileData = TodoTileDataCreator.CreateTile(
                                    todoItem.Description, todoItem.DueDate);

    string url = string.Format("/TodoList/TodoItemView.xaml?{0}={1}",
                                    TaskScheduler.TodoItemIdQueryKey,
                                    todoItem.Id);

    if (createTile)
    {
        /* Creating a shell tile takes the user to the start experience. */
        ShellTile.Create(new Uri(url, UriKind.Relative), tileData);
    }
    else
    {
        ShellTile shellTile = ShellTile.ActiveTiles.Where(
         tile => tile.NavigationUri.ToString()
                       .Contains(url)).FirstOrDefault();

        if (shellTile != null)
        {
            shellTile.Update(tileData);
        }
        Navigate(todoListUrl);

    }
}

Other -----------------
- Windows Phone 8 : Scheduled Tasks - Using Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - Background Agent Types
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Reusing the Transition Attached Properties
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Using Windows Phone Toolkit Transitions
- Windows Phone 8 : Messaging - Composing a New Message (part 8) - Checking for New Mail
- Windows Phone 8 : Messaging - Composing a New Message (part 7) - Adding Emoticons and Clip Art
- Windows Phone 8 : Messaging - Composing a New Message (part 6) - Adding Recipients Through CC and Blind CC
- Windows Phone 8 : Messaging - Composing a New Message (part 5) - Setting Message Priority
- Windows Phone 8 : Messaging - Composing a New Message (part 4) - Removing a Message Attachment
- Windows Phone 8 : Messaging - Composing a New Message (part 3) - Sending a Picture from the Camera
 
 
25 Inspiring Game of Thrones Quotes
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer