Windows 7 taskbar (Overlay Icon, Thumbnail Toolbar, and Progress Bar) developed by WPF 4)

Source: Internet
Author: User

In the previous article, we introduced how to develop the Windows 7 jump list in WPF 4. This article will continue with the other functions of the taskbar in WPF 4: Overlay Icon and Progress Bar) and the Thumbnail Toolbar (Thumbnail Toolbar. For API development for these functions, see Windows 7 taskbar Development Series summary.

TaskbarItemInfo

In System. windows. in the Shell namespace, The TaskbarItemInfo class contains all the above Windows 7 taskbar development functions. Through this class, We Can Customize various functions of the software taskbar. For details about the class Members, refer to TaskbarItemInfo Members.

ThumbButtonInfo

Similarly, in the System. Windows. Shell namespace, The ThumbButtonInfo class provides the function for developing the thumbnail toolbar. For details about the usage of the class Members, refer to ThumbButtonInfo Members.

Overlay Icon)

When developing an Overlay Icon through APIS, you must simply call the SetOverlayIcon method. Development in WPF 4 is still very simple. You only need to assign the Icon value to the Overlay attribute of the TaskbarItemInfo class in XAML, as shown in the following code:

<Window.TaskbarItemInfo>        <TaskbarItemInfo x:Name="taskBar"                          Overlay="Resources/Question.ico"                         Description="Taskbar Items Sample">        </TaskbarItemInfo></Window.TaskbarItemInfo>

In this way, a "Question mark icon" is added to the program icon ":

Thumbnail Toolbar (Thumbnail Toolbar)

Next we will add a thumbnail toolbar for the program, add the shield button (Safe. ico) to it, and click it to change the "Question mark icon ". First, add ThumbButtonInfo content based on the previous code to load the buttons for the toolbar:

<Window.TaskbarItemInfo>        <TaskbarItemInfo x:Name="taskBar"                          Overlay="Resources/Question.ico"                         Description="Taskbar Items Sample">            <TaskbarItemInfo.ThumbButtonInfos>                    <ThumbButtonInfo x:Name="changeIcon"
DismissWhenClicked="True" Click="changeIcon_Click" Description="Change overlay icon" ImageSource="Resources/Safe.ico"/> </TaskbarItemInfo.ThumbButtonInfos> </TaskbarItemInfo></Window.TaskbarItemInfo>

In the codeDismissWhenClickedThe function is to determine whether the thumbnail window is closed after the button is clicked (the default value is False );DescriptionButton description;ImageSourceButton icon;ClickAn event is triggered when you click. The following code triggers the changeIcon_Click event after a click:

private ImageSource IconToBitmapSource(Icon img) {    Bitmap bitmap = img.ToBitmap();    IntPtr hBitmap = bitmap.GetHbitmap();    ImageSource bitmapSource =                Imaging.CreateBitmapSourceFromHBitmap(                     hBitmap, IntPtr.Zero, Int32Rect.Empty,                     BitmapSizeOptions.FromEmptyOptions());    return bitmapSource;}private void changeIcon_Click(object sender, EventArgs e){    taskBar.Overlay = IconToBitmapSource(Win7TaskbarDemo.Properties.Resources.Safe); }

In the code, IconToBitmapSource is a function that converts System. Drawing. Icon to System. Windows. Media. ImageSource. You can convert the Icon image in the program to ImageSource and assign it to Overlay. If you want to cancel the Overlay icon, set taskBar. Overlay to null. It can be seen that Overlay replacement is also very simple.

 Running EffectEffect after clicking

Progress Bar)

In WPF 4, the taskbar progress bar status is still five (as shown in the following table ). To change the progress bar status of the taskbar, add a button to the toolbar of the thumbnail to change the color of the progress bar when you click it.

<Window.TaskbarItemInfo>        <TaskbarItemInfo x:Name="taskBar"                          Overlay="Resources/Question.ico"                         Description="Taskbar Items Sample">            <TaskbarItemInfo.ThumbButtonInfos>                <ThumbButtonInfoCollection>                    <ThumbButtonInfo x:Name="changeIcon"                                     DismissWhenClicked="True"                                     Click="changeIcon_Click"                                     Description="Change overlay icon"                                     ImageSource="Resources/Safe.ico"/>                    <ThumbButtonInfo x:Name="progressState"                                     DismissWhenClicked="False"                                     Click="progressState_Click"                                     Description="Change progress state"                                     ImageSource="Resources/Error.ico"/>                </ThumbButtonInfoCollection>            </TaskbarItemInfo.ThumbButtonInfos>        </TaskbarItemInfo></Window.TaskbarItemInfo>

Add some content for the progressState_Click eventProgressStateAdjust the progress bar status.ProgressValueSet the progress value:

private void progressState_Click(object sender, EventArgs e){    taskBar.ProgressState = TaskbarItemProgressState.Error;    taskBar.ProgressValue = 0.4;}

Click the comparison chart before and after:

Thumbnail Adjustment

In new WPF 4, we can adjust the content displayed in the thumbnail of the program window through the ThumbnailClipMargin attribute of TaskbarItemInfo. As shown in, by default, the thumbnail displays the full picture of the program window. The following uses the ThumbnailClipMargin value in XAML to make the thumbnail display only the "Reset" button section.

<Window.TaskbarItemInfo>        <TaskbarItemInfo x:Name="taskBar"                         ThumbnailClipMargin="120,90,120,40"                         Overlay="Resources/Question.ico"                         Description="Taskbar Items Sample" /></Window.TaskbarItemInfo>

:

So far, the development of Windows 7 taskbar in WPF 4 has been introduced. Other New Features of WPF 4 will be introduced in the future. Stay tuned! Next week, VS2010 will be officially released. You can try it yourself ~

References

1. Windows 7 taskbar Development Series Summary

Http://www.cnblogs.com/gnielee/archive/2010/03/21/1691101.html

2. TaskbarItemInfo Class

Http://msdn.microsoft.com/en-us/library/dd783827 (v = VS.100). aspx

3. ThumbButtonInfo Class

Http://msdn.microsoft.com/en-us/library/dd783604 (v = VS.100). aspx

Source code download

Win7TaskbarDemo.VS2010.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.