Windows 7 Taskbar Managed

Document Sample
Windows 7 Taskbar Managed Powered By Docstoc
					Windows 7: Taskbar: Managed
Windows 7: Taskbar: Managed



Table of Contents

Windows 7: Taskbar: Managed ......................................................... 1
Exercise 1 Experiment with the New Windows 7 Taskbar Features .................................... 2
Windows 7: Taskbar: Managed



Windows 7: Taskbar: Managed

Objectives                    After completing this lab, you will be better able to:
                                      Providing visual progress and status indicators using taskbar progress
                                       bars and overlay icons

                                      Remotely controlling a window from the taskbar thumbnail using
                                       thumbnail toolbars

                                      Customizing the taskbar thumbnail and live preview using thumbnail
                                       clips and fully custom on-demand thumbnails

                                      Quickly accessing common tasks and frequent destinations using jump
                                       list tasks, system categories and custom categories


                              The new taskbar is a differentiating opportunity that allows applications to
Scenario                      shine on the Windows 7 platform. It is the end user’s primary point-of-contact
                              for initiating and managing activities. Thus, the integration of new taskbar
                              features into modern Windows 7 applications is a critically important goal.

                              The consolidation of features into the new taskbar user interface is designed to
                              provide a cleaner look to Windows, reduce the number of concepts users must
                              learn in order to interact with the system, ease discoverability of key features,
                              tasks and destinations, and make common end-user scenarios more accessible.



Estimated Time to             90 Minutes
Complete This Lab

Computer used in this
Lab                                     Win7Devs


                              The username for the Administrator account on this computer is Win7User and
                              the password is: pass@word1




                                               Page 1 of 15
Windows 7: Taskbar: Managed


Exercise 1
Experiment with the New Windows 7 Taskbar Features

Scenario
In this exercise, you will experiment with the new Windows 7 taskbar features. You will extend a showcase
application that demonstrates the use of the new taskbar functionality to provide a taskbar progress bar, overlay
icon, custom thumbnail, jump list and more. Most of the application’s user interface is already implemented; you
will have to fill in the missing parts to interact with the Windows 7 taskbar using the Windows API Code Pack.

To begin this exercise, open the TaskbarConcepts_Starter solution
(“C:\Labs\Managed\Taskbar\TaskbarConcepts_Starter\TaskbarConcepts_Starter.sln”) in Visual Studio.

In the interests of brevity and simplicity, the demo application does not demonstrate best practices of WPF UI
development, nor does it exhibit the best design guidelines for working with the Windows 7 Taskbar. For more
information, consult the Windows 7 User Experience Guidelines (Taskbar) at http://msdn.microsoft.com/en-
us/library/aa511446.aspx and the Taskbar Extensions article at http://msdn.microsoft.com/en-
us/library/dd378460(VS.85).aspx



Tasks                        Detailed Steps
Complete the following       Note: In this task, you will toggle an overlay icon on the application’s taskbar button
task on:                     when an icon is selected by the user.

     Win7Devs                a.   Navigate to the Overlays.xaml.cs code file and locate the
                                  ShowOrHideOverlayIcon method.
1.   Using Taskbar           b.   In the method’s code, check whether the ShowOverlay checkbox is checked.
     Overlay Icons
                             c.   If the checkbox is checked, retrieve the currently selected icon from the list using
                                  the iconsList.SelectedItem property, and if it is not null, pass it to the
                                  TaskbarManager.Instance.SetOverlayIcon method along with an appropriate
                                  textual description.

                             Note: This will cause an overlay icon to appear in the bottom-right corner of the
                             application’s taskbar button, providing an immediate status indicator without the
                             need to switch to the application’s window. This feature is used by Windows Live
                             Messenger to display online availability status, by Microsoft Office Outlook 14 to
                             display the new mail notification and by many other applications.

                             d.   If the checkbox is not checked, pass null to the same method to clear the overlay
                                  icon. (You may also pass null for the textual description.)

                             e.   The complete code should be similar to the following:

                                      C#
                                      if (ShowOverlay.IsChecked.Value)
                                      {


                                                    Page 2 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                                    Icon icon = iconsList.SelectedItem as Icon;
                                    if (icon != null)
                                        TaskbarManager.Instance.SetOverlayIcon(
                                          icon, "icon" + iconsList.SelectedIndex.ToString());
                                  }
                                  else
                                  {
                                    TaskbarManager.Instance.SetOverlayIcon(null, null);
                                  }


                         f.   Compile and run the application.

                         g.   Navigate to the Overlay Icon tab, check the checkbox and make sure that an
                              overlay icon appears on the application’s taskbar button. For example:

                         h.   Select another icon and make sure that the overlay icon changes.

                         i.   Clear the checkbox and make sure that the overlay icon is cleared as well.

2.   Using Taskbar       Note: In this task, you will set the state and value of the application’s taskbar
     Progress Bars       progress bar when the user selects the progress state from a combo box or changes
                         the value by using a slider.

                         a.   Navigate to the ProgressBar.xaml.cs code file and locate the UpdateProgress
                              method.

                         b.   In the method’s code, check whether the ShowProgressBar checkbox is checked.

                         c.   If the checkbox is checked, use the TaskbarManager.Instance.SetProgressValue
                              method to set the progress value to the value of the progressSlider.Value
                              property. Use the number 100 for the maximum progress value.

                         d.   If the checkbox is checked, use the TaskbarManager.Instance.SetProgressState
                              method to set the progress state to the value of the
                              ProgressStateSelection.SelectedItem property.

                         Note: This will cause a progress bar to appear in the application’s taskbar button,
                         providing an immediate progress indicator without the need to switch to the
                         application’s main window. This feature is extensively used by Windows Explorer
                         when performing file operations, by Internet Explorer when downloading files and by
                         other Windows applications.

                         e.   If the checkbox is not checked, use the method from the previous step to set the
                              progress state to TaskbarProgressState.NoProgress, clearing the progress bar.

                         f.   The complete code should be similar to the following:

                                  C#
                                  if (ShowProgressBar.IsChecked.Value)
                                  {


                                               Page 3 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                                    TaskbarManager.Instance.SetProgressValue((int)progressSlider.Value,
                                  100);
                                    TaskbarManager.Instance.SetProgressState(
                                       (TaskbarProgressBarState)ProgressStateSelection.SelectedItem);
                                  }
                                  else
                                  {
                                    TaskbarManager.Instance.SetProgressState(
                                       TaskbarProgressBarState.NoProgress);
                                  }


                         g.   Navigate to the ProgressStateSelection_SelectionChanged method.

                         h.   In the method’s code, check whether the ProgressStateSelection.SelectedItem
                              property is equal to TaskbarProgressState.NoProgress.

                         i.   If it is equal, set the ShowProgressBar.IsChecked property to false.

                         j.   Otherwise, set the same property to true.

                         k.   Finally, call the UpdateProgress method you wrote earlier to update the taskbar
                              progress state and value if necessary.

                         l.   The complete code should be similar to the following:

                                  C#
                                  if ((TaskbarProgressBarState)ProgressStateSelection.SelectedItem
                                      == TaskbarProgressBarState.NoProgress)
                                  {
                                      ShowProgressBar.IsChecked = false;
                                  }
                                  else
                                  {
                                      ShowProgressBar.IsChecked = true;
                                  }
                                  UpdateProgress();


                         m. Navigate to the ShowProgressBar_Click method.

                         n.   In the method’s code, check whether the ShowProgressBar.IsChecked property is
                              true.

                         o.   If it is, set the ProgressStateSelection.SelectedItem property to
                              TaskbarProgressState.Normal.

                         p.   Otherwise, set the same property to TaskbarProgressState.NoProgress.

                         q.   Finally, call the UpdateProgress method you wrote earlier to update the taskbar




                                                Page 4 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                              progress state and value if necessary.

                         r.   The complete code should be similar to the following:

                                  C#
                                  if (ShowProgressBar.IsChecked.Value)
                                  {
                                      ProgressStateSelection.SelectedItem = TaskbarProgressBarState.Normal;
                                  }
                                  else
                                  {
                                      ProgressStateSelection.SelectedItem =
                                  TaskbarProgressBarState.NoProgress;
                                  }
                                  UpdateProgress();


                         s.   Compile and run the application.

                         t.   Navigate to the Progress Bar tab, check the checkbox and move the slider to the
                              middle. Make sure that a taskbar progress bar is displayed and updated
                              accordingly.

                         u.   Select a different progress state from the combo box and make sure the progress
                              state changes.

                         v.   Clear the checkbox and make sure the progress bar is cleared as well.

3.   Using Thumbnail     Note: In this task, you will create taskbar thumbnail toolbar buttons to navigate
     Toolbars            images displayed in the main application window.

                         a.   Navigate to the ToolbarButtons.xaml.cs code file and locate the
                              CreateToolbarButtons method. You will create four thumbnail toolbar buttons
                              for image navigation, and add these buttons to the application’s thumbnail
                              toolbar. As a result, the user will be able to navigate the images from the taskbar
                              thumbnail, without switching to the application’s main window.

                         Note: Thumbnail toolbars are used by Windows Media Player to provide convenient
                         navigation between tracks in the current playlist without switching to the Media
                         Player window. This effectively replaces the need for the Media Player taskbar desk-
                         band, which introduced clutter into the Windows taskbar and consumed a significant
                         amount of screen estate that can be used for taskbar buttons.

                         b.   In the method’s code, assign the buttonFirst member variable with a new
                              instance of the ThumbnailToolbarButton class. Pass to the constructor the
                              TaskbarConcepts.Resources.first image and the string “First Image” as the
                              tooltip.

                         c.   Set the buttonFirst.Enabled property to false.




                                                Page 5 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                         d.   Register the buttonFirst_Click method to the buttonFirst.Click event.

                         e.   Repeat steps 2-4 for the buttonPrevious member variable with the
                              TaskbarConcepts.Resources.prevArrow image and the string “Previous Image”.

                         f.   Repeat steps 2 and 4 (without step 3) for the buttonNext member variable with
                              the TaskbarConcepts.Resources.nextArrow image and the string “Next Image”.

                         g.   Repeat steps 2 and 4 (without step 3) for the buttonLast member variable with
                              the TaskbarConcepts.Resources.last image and the string “Last Image”.
                         h.   Call the TaskbarManager.Instance.ThumbnailToolbars.AddButtons method,
                              passing the application’s main window handle as the first parameter, followed by
                              the buttons created in the previous steps. This step creates the taskbar
                              thumbnail toolbar.

                         i.   The complete code should be similar to the following:

                                  C#
                                  buttonFirst = new ThumbnailToolbarButton(
                                    TaskbarConcepts.Resources.first, "First Image");
                                  buttonFirst.Enabled = false;
                                  buttonFirst.Click += buttonFirst_Click;

                                  buttonPrevious = new ThumbnailToolbarButton(
                                    TaskbarConcepts.Resources.prevArrow, "Previous Image");
                                  buttonPrevious.Enabled = false;
                                  buttonPrevious.Click += buttonPrevious_Click;

                                  buttonNext = new ThumbnailToolbarButton(
                                    TaskbarConcepts.Resources.nextArrow, "Next Image");
                                  buttonNext.Click += buttonNext_Click;

                                  buttonLast = new ThumbnailToolbarButton(
                                    TaskbarConcepts.Resources.last, "Last Image");
                                  buttonLast.Click += buttonLast_Click;

                                  TaskbarManager.Instance.ThumbnailToolbars.AddButtons(
                                    new WindowInteropHelper(Application.Current.MainWindow).Handle,
                                    buttonFirst, buttonPrevious, buttonNext, buttonLast);


                         j.   Compile and run the application.

                         k.   Navigate to the Thumbnail Toolbar tab.

                         l.   Hover over the application’s taskbar button until the thumbnail is shown. Use
                              the four thumbnail toolbar buttons to navigate between the images.




                                               Page 6 of 15
Windows 7: Taskbar: Managed


Tasks                       Detailed Steps
4.   Using Live Thumbnail   Note: In this task, you will customize live thumbnails (and previews) of the
     Previews               application’s window and provide the displayed thumbnail lazily (on demand).

                            a.   Navigate to the Thumbnail.xaml.cs code file and locate the
                                 createOnDemandThumbnail_Click method.

                            b.   In the method’s code, check whether the trickyBorder visual element has a
                                 thumbnail preview. You can use the Utilities.HasThumbnailPreview method for
                                 this purpose.
                            c.   If it doesn’t have a preview yet, continue to the following steps. Otherwise,
                                 return from the method—there is already a thumbnail for this element and
                                 there’s no need to create it again.

                            d.   Calculate the offset of the trickyBorder visual element from the application’s
                                 main window (you can retrieve the main window frame using the
                                 Application.Current.MainWindow property). To calculate the offset, you can use
                                 the helper method Utilities.GetOffset.

                            Note: The reason for calculating the offset is that we want the actual taskbar
                            thumbnail to display only the image itself, and not the entire window frame. In this
                            case, the taskbar thumbnail APIs require the offset from the application’s main
                            window frame to be specified. Thumbnail customization can be useful if you want to
                            draw attention to a specific part of the window when it’s displayed as a thumbnail, or
                            when you want to dynamically decide which part of the window to display in the
                            thumbnail. Technically, it’s not binding for you to display a part of your window in the
                            thumbnail—you could provide a completely custom image—but this has the potential
                            to confuse users.

                            e.   Create a new instance of the TabbedThumbnail class and pass to its constructor
                                 the application’s main window, the trickyBorder visual element and the offset
                                 calculated in the previous step.

                            f.   Use the TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview
                                 method to add the newly created preview object to the taskbar.

                            g.   Register for the TabbedThumbnailBitmapRequested event of the
                                 TabbedThumbnail instance using the
                                 TabbedThumbnail_TabbedThumbnailBitmapRequested method. This means that
                                 we are not providing the thumbnail bitmap statically; instead, the DWM will call
                                 back into our event implementation so that we provide the bitmap dynamically,
                                 only when it’s needed.

                            h.   Set the Tooltip property of the TabbedThumbnail instance to a string of your
                                 choice.

                            i.   The complete code should be similar to the following:

                                     C#
                                     if (!Utilities.HasThumbnailPreview(trickyBorder))


                                                  Page 7 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                                  {
                                      Vector offset = Utilities.GetOffset(
                                        Application.Current.MainWindow, trickyBorder);
                                      TabbedThumbnail preview = new TabbedThumbnail(
                                        Application.Current.MainWindow, trickyBorder, offset);

                                  TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(preview
                                  );

                                      preview.TabbedThumbnailBitmapRequested +=
                                        TabbedThumbnail_TabbedThumbnailBitmapRequested;

                                      preview.Tooltip = "This bitmap is created and returned on demand";
                                  }


                         j.   Navigate to the removeOnDemandThumbnail_Click method.

                         k.   In the method’s code, retrieve the TabbedThumbnail object corresponding to
                              the trickyBorder visual element’s thumbnail using the
                              TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview method.

                         l.   If the retrieved instance is not null, use the
                              TaskbarManager.Instance.TabbedThumbnail.RemoveThumbnailPreview method
                              to remove the thumbnail preview.

                         m. The complete code should be similar to the following:

                                  C#
                                  TabbedThumbnail preview =

                                  TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(trickyBo
                                  rder);
                                  if (preview != null)

                                  TaskbarManager.Instance.TabbedThumbnail.RemoveThumbnailPreview(pre
                                  view);


                         n.   Navigate to the TabbedThumbnail_TabbedThumbnailBitmapRequested method.

                         o.   In the method’s code, check whether the _sneakySource member variable is null.

                         p.   If it is, assign to it a new BitmapImage object, call its BeginInit method, set its
                              DecodePixelHeight property to the number 200, set its UriSource property to a
                              new Uri instance initialized with the string
                              “pack://application:,,,/assets/SpeedyGonzalez.jpg” and then call its EndInit
                              method.



                                                Page 8 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                         q.   Finally, use the TabbedThumbnail.SetImage method of the event arguments
                              parameter and pass to it the _sneakySource member variable.

                              The complete code should be similar to the following:

                                  C#
                                  if (_sneakySource == null)
                                  {
                                      _sneakySource = new BitmapImage();
                                      _sneakySource.BeginInit();
                                      _sneakySource.DecodePixelHeight = 200;
                                      _sneakySource.UriSource =
                                        new Uri("pack://application:,,,/assets/SpeedyGonzales.jpg");
                                      _sneakySource.EndInit();
                                  }
                                  e.TabbedThumbnail.SetImage(_sneakySource);


                         r.   Navigate to the createThumbnail_Click method. In this method, we will use a
                              statically set bitmap for the thumbnail, without registering for the event that is
                              invoked by the DWM. As a result, we will have to manually invalidate the
                              thumbnail whenever it becomes stale.

                         s.   Repeat steps 2-8 for the image visual element, but this time do not register for
                              the TabbedThumbnailBitmapRequested event. Instead, call the
                              TaskbarManager.Instance.TabbedThumbnail.SetActiveTab method and pass to it
                              the newly created TabbedThumbnail instance.

                                  The complete code should be similar to the following:

                                  C#
                                  if (!Utilities.HasThumbnailPreview(image))
                                  {
                                      Vector offset = Utilities.GetOffset(
                                        Application.Current.MainWindow, image);
                                      TabbedThumbnail preview = new TabbedThumbnail(
                                        Application.Current.MainWindow, image, offset);

                                  TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(preview
                                  );
                                     preview.Tooltip = "This image will be replaced and invalidated";
                                     TaskbarManager.Instance.TabbedThumbnail.SetActiveTab(preview);
                                  }


                         t.   Navigate to the removeThumbnail_Click method.

                         u.   Repeat steps 10-12 for the image visual element.



                                                Page 9 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                         v.   The complete code should be similar to the following:

                                  C#
                                  TabbedThumbnail preview =

                                  TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(image);
                                  if (preview != null)

                                  TaskbarManager.Instance.TabbedThumbnail.RemoveThumbnailPreview(pre
                                  view);


                         w. Navigate to the invalidateThumbnail_Click method. The invalidation is necessary
                            because we did not register an event handler for the thumbnail bitmap, and
                            therefore the bitmap remains static until we explicitly invalidate it.

                         x.   In the method’s code, check whether there is a thumbnail preview for the image
                              visual element (see steps 11-12 for an example).

                         y.   If there is, use the InvalidatePreview method of the resulting TabbedThumbnail
                              object to invalidate the thumbnail preview.

                         z.   The complete code should be similar to the following:

                                  C#
                                  TabbedThumbnail preview =

                                  TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(image);
                                  if (preview != null)
                                      preview.InvalidatePreview();


                         aa. Compile and run the application.

                         bb. Navigate to the Thumbnail Preview tab and click the ‘Add as thumbnail’ button
                             in the ‘Thumbnail with Callback’ group.

                         cc. Hover over the application’s taskbar button and ensure that the thumbnail
                             displays an image instead of the black rectangle.

                         dd. Click the ‘Remove thumbnail’ button in the ‘Thumbnail with Callback’ group and
                             ensure that the application’s taskbar thumbnail and live preview are back to the
                             default (the entire window).

                         ee. Click the ‘Add as thumbnail’ button in the ‘Tabbed Thumbnail’ group.

                         ff. Hover over the application’s taskbar button and ensure that the thumbnail and
                             live preview reflect the current image in the main window.

                         gg. Click the ‘Update image’ button in the ‘Tabbed Thumbnail’ group and notice that



                                              Page 10 of 15
Windows 7: Taskbar: Managed


Tasks                     Detailed Steps
                                the thumbnail is not refreshed—it still displays the previous image.

                          hh. Click the ‘Invalidate thumbnail’ button in the ‘Tabbed Thumbnail’ group and
                              ensure that the thumbnail is updated to reflect the new image.

                          ii.   Finally, click the ‘Remove thumbnail’ button in the ‘Tabbed Thumbnail’ group
                                and ensure that the application’s taskbar thumbnail and live preview are back to
                                the default (the entire window).

5.   Using Taskbar Jump   Note: In this task, you will add the functionality to support adding user tasks, custom
     Lists                categories and destinations to the application’s jump list, as well as clearing the list of
                          user tasks.

                          a.    Navigate to the JL.xaml.cs code file and locate the OnAddTask method.

                          b.    In the method’s code, create an instance of the JumpListLink class and pass to its
                                constructor the path to notepad.exe (use the Environment.GetFolderPath
                                method to determine the location of the System32 directory in which the
                                Notepad executable resides), and the string “Open Notepad” for the link’s title.

                          c.    Set the IconReference property of the newly created instance to a new instance
                                of the IconReference class, and pass to the constructor the path to notepad.exe
                                (obtained in the previous step), and the number 0 as the icon index.

                          d.    Repeat steps 2 and 3 to create links to calc.exe and mspaint.exe with the
                                corresponding “Open Calculator” and “Open Paint” title strings.

                          e.    Call the JumpList.AddUserTasks method and pass to it the Notepad and
                                Calculator link objects, followed by a new instance of JumpListSeparator,
                                followed by the Paint link object.

                          Note: As a result, you’ve added common user tasks to your application’s jump list. In
                          practice, it would be uncommon for an application to include user tasks that launch
                          unrelated applications. Instead, common user tasks would include launching the
                          application with different command line arguments, navigating to a specific area in
                          the application, or even specifying commands for a running instance of the
                          application. For example, Windows Live Messenger uses jump list tasks for changing
                          the user’s online availability status.

                          f.    Finally, call the JumpList.Refresh method to refresh the application’s jump list.

                          g.    The complete code should be similar to the following:

                                    C#
                                    string systemFolder = Environment.GetFolderPath(
                                       Environment.SpecialFolder.System);

                                    IJumpListTask notepadTask = new JumpListLink(
                                       System.IO.Path.Combine(systemFolder, "notepad.exe"), "Open Notepad")
                                    {
                                       IconReference = new IconReference(


                                                 Page 11 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                                       Path.Combine(systemFolder, "notepad.exe"), 0)
                                  };
                                  IJumpListTask calcTask = new JumpListLink(
                                     Path.Combine(systemFolder, "calc.exe"), "Open Calculator")
                                  {
                                     IconReference = new IconReference(
                                       Path.Combine(systemFolder, "calc.exe"), 0)
                                  };
                                  IJumpListTask paintTask = new JumpListLink(
                                     Path.Combine(systemFolder, "mspaint.exe"), "Open Paint")
                                  {
                                     IconReference = new IconReference(
                                       Path.Combine(systemFolder, "mspaint.exe"), 0)
                                  };

                                  JumpList.AddUserTasks(
                                    notepadTask, calcTask, new JumpListSeparator(), paintTask);
                                  JumpList.Refresh();


                         h.   Navigate to the JumpList property.

                         i.   In the property’s get accessor, check if the _jumpList member variable is null.

                         j.   If it is, set its value to the result of the JumpList.CreateJumpList method, set its
                              KnownCategoryToDisplay property to JumpListKnownCategoryType.Recent if the
                              showRecent.IsChecked property is true or JumpListKnownCategoryType.Frequent
                              if it’s false; finally, call the JumpList.Refresh method to refresh the jump list.

                         Note: There are two system categories that you can opt in to use by default: the
                         Recent category, which shows documents most recently accessed by your application,
                         and the Frequent category, which shows documents most frequently accessed. Using
                         both categories is discouraged and the managed wrapper doesn’t allow it at all.

                         In order to have items appear in the Recent or Frequent categories, your application
                         needs a properly defined file-type association in the Windows Registry (although it
                         does not have to be the default handler for that file-type). The sample application can
                         be registered to handle PNG image files. For more information about file-type
                         associations, consult http://msdn.microsoft.com/en-us/library/dd758090.aspx
                         k.   Return the value of the _jumpList member variable from the get accessor.

                         l.   The complete code should be similar to the following:

                                  C#
                                  if (_jumpList == null)
                                  {
                                      _jumpList = JumpList.CreateJumpList();
                                      _jumpList.KnownCategoryToDisplay =
                                        showRecent.IsChecked.Value ?


                                               Page 12 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                                        JumpListKnownCategoryType.Recent :
                                        JumpListKnownCategoryType.Frequent;
                                    _jumpList.Refresh();
                                  }
                                  return _jumpList;


                         m. Navigate to the showRecent_Click method.

                         n.   In the method’s code, set the JumpList.KnownCategoryToDisplay property
                              according to the same logic as in step 10 above, and call the JumpList.Refresh
                              method.

                         o.   The complete code should be similar to the following:

                                  C#
                                  JumpList.KnownCategoryToDisplay =
                                    showRecent.IsChecked.Value ?
                                      JumpListKnownCategoryType.Recent :
                                      JumpListKnownCategoryType.Frequent;
                                  JumpList.Refresh();


                         p.   Navigate to the OnClearTasks method.

                         q.   In the method’s code, call the JumpList.ClearAllUserTasks method to clear the
                              jump list from all user tasks.

                         r.   Call the JumpList.Refresh method for the changes to take effect.

                         s.   The complete code should be similar to the following:

                                  C#
                                  JumpList.ClearAllUserTasks();
                                  JumpList.Refresh();


                         t.   Navigate to the createCategory_Click method.

                         u.   In the method’s code, assign to the _currentCategory member variable a new
                              instance of the JumpListCustomCategory class, passing to its constructor the
                              name of the category obtained from the txtCategory member variable.

                         Note: Custom categories are an advanced feature that can be used by an application
                         to provide more than just the Recent or Frequent system categories. For example, an
                         email application might provide Inbox, Follow-up and other custom categories in
                         which messages are grouped.
                         v.   Use the JumpList.AddCustomCategories method and pass to it the newly created
                              category.




                                               Page 13 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                         w. Call the JumpList.Refresh method to commit the changes.

                         x.   Set the IsEnabled property of the createCategoryItem, createCategoryLink,
                              txtCategoryItem and txtCategoryLink member variables to true.

                         y.   The complete code should be similar to the following:

                                  C#
                                  _currentCategory = new JumpListCustomCategory(this.txtCategory.Text);
                                  JumpList.AddCustomCategories(_currentCategory);
                                  JumpList.Refresh();

                                  this.createCategoryItem.IsEnabled = true;
                                  this.createCategoryLink.IsEnabled = true;
                                  this.txtCategoryItem.IsEnabled = true;
                                  this.txtCategoryLink.IsEnabled = true;


                         z.   Navigate to the createCategoryItem_Click method.

                         aa. In the method’s code, call the CheckFileName method and pass to it the Text
                             property of the txtCategoryItem member variable. If the method returns false,
                             return from this method without doing anything.

                         bb. Otherwise, create a new instance of the JumpListItem class and pass to its
                             constructor the result of calling the GetTempFileName method with the
                             txtCategoryItem.Text property. (The latter method creates a new temporary file
                             with an appropriate file name.)

                         cc. Use the AddJumpListItems method of the _currentCategory member variable
                             and pass to it the newly created JumpListItem instance.

                         dd. Call the JumpList.Refresh method to commit the changes to the jump list.

                         ee. The complete code should be similar to the following:

                                  C#
                                  if (!CheckFileName(txtCategoryItem.Text))
                                      return;

                                  JumpListItem jli = new
                                  JumpListItem(GetTempFileName(txtCategoryItem.Text));
                                  _currentCategory.AddJumpListItems(jli);
                                  JumpList.Refresh();


                         ff. Navigate to the createCategoryLink_Click method.

                         gg. Repeat steps 27-31, but instead of using txtCategoryItem use txtCategoryLink
                             and instead of using JumpListItem use JumpListLink. The JumpListLink



                                              Page 14 of 15
Windows 7: Taskbar: Managed


Tasks                    Detailed Steps
                               constructor requires an additional title parameter—you should pass the
                               txtCategoryLink.Text property for this parameter.

                         Note: The difference between shell items and shell links (represented as JumpListItem
                         and JumpListLink in the managed wrapper, and by IShellItem and IShellLink in the
                         underlying COM Shell APIs) is that a shell item contains only a path to a document
                         that your application is registered to handle, but a shell link contains additional
                         information and serves as a shortcut, including the application to launch, command-
                         line arguments to pass to that application, a shortcut icon and other properties.

                         hh. The complete code should be similar to the following:

                                   C#
                                   if (!CheckFileName(txtCategoryItem.Text))
                                       return;

                                   JumpListLink jli = new JumpListLink(
                                     GetTempFileName(txtCategoryLink.Text), txtCategoryLink.Text);
                                   _currentCategory.AddJumpListItems(jli);
                                   JumpList.Refresh();


                         ii.   Compile and run the application.

                         jj.   Navigate to the Jump List tab and click the ‘Ensure type registration’ button. The
                               application will register the .png file association with itself in the Windows
                               Registry. This may cause a User Account Control consent prompt—confirm the
                               action if prompted.

                         kk. Check the ‘Show recent category’ checkbox and click the button above it. In the
                             common file dialog, select the Windows7 PNG file
                             (C:\Users\Win7User\Pictures\Windows7.png). Ensure that the application’s
                             jump list now contains the selected PNG file in the Recent category.

                         ll.   Click the ‘Add Tasks’ button and ensure that the jump list now contains links to
                               Notepad, Calculator and Paint (and that there is a separator between the first
                               two and the last one).

                         mm.              Enter ‘Important’ in the category name textbox and click the
                            ‘Create’ button.

                         nn. Enter ‘Activity report’ in the item textbox and click the ‘Add ShellItem’ button.
                             Ensure that the jump list now contains a category called ‘Important’ with a single
                             item called ‘Activity report’.




                                                Page 15 of 15