Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
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

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
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

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

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
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 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro