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 3) - Debugging Scheduled Tasks

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
9/10/2014 4:24:31 AM
Debugging Scheduled Tasks

Debugging a task agent is done by calling the ScheduledActionService.LaunchForTest method. Calling LaunchForTest is a way of forcing the OS to run your task agent. LaunchForTest accepts two parameters: the name of the scheduled task and a TimeSpan that indicates the delay before the task agent is invoked. By specifying TimeSpan.Zero, the task agent is invoked immediately.

With the TestAgentCommand wired up to the UI, you can instruct the OS to launch the task agent, allowing you to step into the task agent’s OnInvoke method. The task agent for the sample is discussed later in this section.

The viewmodel relies on a custom IDeviceProperties interface, which allows the viewmodel to retrieve the Windows Live anonymous ID.

TodoListView XAML

The TodoListView XAML contains a LongListSelector that is bound to the GroupedTodoItems property of the viewmodel (see Listing 5). The LongListSelector’s ItemTemplate uses a TextBlock to display the Description property of each TodoItem. When the user taps the description, the EditItemCommand is executed, and the Id of the TodoItem is passed as a command parameter.

The LongListSelector's GroupHeaderTemplate contains a Border whose background is determined by the Overdue property of the group key, which is a DateGroupingKey instance.

LISTING 5. TodoListView.xaml (excerpt)


<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <phone:LongListSelector
            ItemsSource="{Binding GroupedTodoItems}"
            IsGroupingEnabled="True"
            Background="Transparent"
            Height="600">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Description}"
                       Margin="12,10,0,10"
                       Style="{StaticResource PhoneTextLargeStyle}"
                       c:Commanding.Event="Tap"
                       c:Commanding.Command="{Binding DataContext.EditItemCommand,
                                                   ElementName=page}"
                       c:Commanding.CommandParameter="{Binding Id}" />
                </StackPanel>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>

        <phone:LongListSelector.GroupHeaderTemplate>
            <DataTemplate>
                <Border Background="Transparent">
                    <Border Background="{Binding Key.Overdue,
                        Converter={StaticResource BooleanToBrushConverter}}"
                                Padding="5"
                                HorizontalAlignment="Left"
                                Margin="0,10,0,0">
                        <TextBlock
                            Text="{Binding Key.DateTime, StringFormat=\{0:d\}}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Style="{StaticResource PhoneTextLargeStyle}"
                            VerticalAlignment="Bottom" />
                    </Border>
                </Border>
            </DataTemplate>
        </phone:LongListSelector.GroupHeaderTemplate>
    </phone:LongListSelector>
</StackPanel>


The custom BooleanToBrushConverter is used to transform the Overdue property of type bool to a brush.

The BooleanToBrushConverter is defined as a page resource as shown:

<phone:PhoneApplicationPage.Resources>
    <ValueConverters:BooleanToBrushConverter
            x:Name="BooleanToBrushConverter"
            BrushIfTrue="Red"
            BrushIfFalse="Blue" />
</phone:PhoneApplicationPage.Resources>

Overdue groups are shown with a red header, and regular groups have a blue header (see Figure 1).

Image

FIGURE 1. To-do items are grouped according to when they are due to expire.

The custom AppBar for the page includes an AppBarHyperlinkButton, which takes the user to the TodoItemView page and allows the user to create a new to-do item. The other viewmodel commands are bound to AppBarMenuItems, as shown:

<u:AppBar>
    <u:AppBarHyperlinkButton
                NavigateUri="/TodoList/TodoItemView.xaml"
                Text="New"
                IconUri="/Images/ApplicationBarIcons/Add.png" />
    <u:AppBar.MenuItems>
        <u:AppBarMenuItem
                Command="{Binding BackupDatabaseCommand}"
                Text="Backup" />
        <u:AppBarMenuItem
                Command="{Binding RestoreDatabaseCommand}"
                Text="Restore" />
        <u:AppBarMenuItem
                    Command="{Binding TestAgentCommand}"
                    Text="test agent" />
    </u:AppBar.MenuItems>
</u:AppBar>

You have seen how the list of to-do items is displayed; the next section examines how new to-do items are created.

TodoItemView and ViewModel

The TodoItemView allows the user to perform the following three tasks:

- Create a new todo item

- Update an existing todo item

- Delete a todo item

The TodoItemViewModel constructor receives the ITodoService, initializes commands, and registers persistent state, as shown:

public TodoItemViewModel(ITodoService todoService)
{
    this.todoService = ArgumentValidator.AssertNotNull(
                                             todoService, "todoService");

    saveCommand = new DelegateCommand<bool>(SaveItem);
    loadItemCommand = new DelegateCommand<int>(LoadItem);
    deleteCommand = new DelegateCommand(obj => DeleteItem());
    RegisterStatefulProperty(ApplicationStateType.Transient,
                             () => TodoDescription);
    RegisterStatefulProperty(ApplicationStateType.Transient,
                             () => TodoDueDate);
}

The viewmodel contains a Description property and a DueDate property, which coincide with the properties of the TodoItem class. When the SaveCommand is executed, the SaveItem method is called. SaveItem uses the ITodoService to persist the TodoItem to the database, and to optionally create a live tile representing the to-do item.

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
 
 
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
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server