Windows 7 jump list developed by WPF 4 (JumpList)

Source: Internet
Author: User

In the "Windows 7 taskbar Development Series" previously written, we developed the application taskbar Through Visual Studio 2008 using the Windows API Code Pack provided by Microsoft, the coming Visual Studio 2010 provides us with a more convenient development method. The new version of WPF 4 only needs to use the XAML code to implement the features of the Windows 7 taskbar. This article introduces JumpList and introduces new features of. NET Framework 4.0.

Compiling JumpList with XAML

In WPF 4, the convenience of developing the taskbar is that you can use XAML to directly write the corresponding functional code, without the need to use APIs to write tedious C # programs. OpenApp. xamlFile is added to the JumpList program we want. The JumpList class provides a method to create a jump list. The JumpTask class can create links in the list. You can compare the JumpList written through APIS. Obviously, the XAML method is simpler and clearer.

<Application x:Class="Win7TaskbarDemo.App"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             StartupUri="MainWindow.xaml">    <Application.Resources>             </Application.Resources>    <JumpList.JumpList>        <JumpList ShowFrequentCategory="True"                  ShowRecentCategory="True">            <JumpTask ApplicationPath="notepad.exe"                       CustomCategory="Microsoft Tools"                       Description="Start Notepad"                       Title="Notepad"                       IconResourcePath="notepad.exe"                       IconResourceIndex="0" />                        <JumpTask ApplicationPath="mspaint.exe"                      CustomCategory="Microsoft Tools"                       Description="Start Paint"                       Title="Paint"                      IconResourcePath="mspaint.exe"                       IconResourceIndex="0" />            <JumpTask ApplicationPath="http://gnielee.cnblogs.com/"                      CustomCategory="Blog Link"                       Description="Go to {GnieTech}"                       Title="Gnie's Blog"                      IconResourcePath="C:\\Program Files\\Internet Explorer\\iexplore.exe" />        </JumpList>    </JumpList.JumpList></Application>

By reading the above program, we can easily see that we have added two applications ("Notepad" and "Drawing version") and a "website link ", the attribute parameters are also very convenient to use.


Use C # To compile JumpList

A simple JumpList is written in the XAML method above. Of course, C # can also achieve the same effect. First, drag two buttons in MainWindow:

<Window x:Class="Win7TaskbarDemo.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="211" Width="363" Icon="/Win7TaskbarDemo;component/Resources/App.ico">        <Grid>        <Button Content="Clear All Tasks" Height="23" HorizontalAlignment="Right" Margin="0,29,59,0"                 Name="ClearBtn" VerticalAlignment="Top" Width="89" Click="ClearBtn_Click" />        <Button Content="Add New Task" Height="23" HorizontalAlignment="Left" Margin="60,29,0,0"                 Name="AddBtn" VerticalAlignment="Top" Width="93" Click="AddBtn_Click" />    </Grid></Window>

Add click events for them separately. One is to add a "Calculator" link for JumpList, and the other is to clear all links. To create a JumpList, you must use the System. Windows. Shell namespace. Is it a bit like Microsoft. WindowsAPICodePack. Shell in the API.

private void AddBtn_Click(object sender, RoutedEventArgs e){   JumpTask jumpTask = new JumpTask();   //Create a new Calculator JumpTask   jumpTask.ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");   jumpTask.IconResourcePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");   jumpTask.Title = "Calculator";   jumpTask.Description = "Start Calculator";   jumpTask.CustomCategory = "New Microsoft Tools";               //Add Calculator to JumpList   JumpList jumpList = JumpList.GetJumpList(App.Current);   jumpList.JumpItems.Add(jumpTask);   jumpList.Apply();}private void ClearBtn_Click(object sender, RoutedEventArgs e){   JumpList jumpList1 = JumpList.GetJumpList(App.Current);   jumpList1.JumpItems.Clear();   jumpList1.Apply();}

The effect of clicking the two buttons respectively:

References

1. Navigation list for Windows 7 taskbar Development (Jump Lists)

Http://www.cnblogs.com/gnielee/archive/2010/03/16/windows7-taskbar-jumplists.html

2. What's New in WPF Version 4

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

3. JumpList Class

Http://msdn.microsoft.com/en-us/library/system.windows.shell.jumplist (v = VS.100). aspx

Source code download

Related Article

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.