5

WPF JumpLists with VB.Net — Donat Studios

 2 years ago
source link: https://donatstudios.com/WPF-VBNet-JumpList-Example
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Simple WPF VB.Net JumpList Example

Today I decided to spruce up a VB.Net application I wrote in college and still use almost daily. In the process of converting it from .Net 2 to .Net 4 I wanted to add a splash of Windows 7 goodness; there were some very simple operations I wanted to add to JumpLists.  The problem I ran into with all the examples I could find is that they either called entirely different applications (the Microsoft examples all called Notepad) or the example was in C#.  The application is in VB.Net and I intend to keep it that way, as it is my .Net language of choice.

The interesting problem with JumpLists is they are just shortcuts.  They call an executable with the specified arguments. Microsoft’s reasoning for this is that they are still available while the program is no longer running. The initial execution of an application placed in the taskbar registers the JumpLists, after which point they are cached by the system and continue to be available even when the application is no longer running. This potentially limits the usefulness of JumpLists as they do start a new instance of your application.  If anyone knows how to catch the arguments on a single instance application, I would be very interested to hear it.  The best I’ve come up with is simply passing messages to my current instance from a new instance and then terminating the second instance, but this is awkward to my eye.

XAML can be used to create JumpLists in the Application.xaml file, which many other examples will demonstrate – but the issue here is there is no way to get the path to the current executable via XAML, so you can only call other executables whom you know the full path to.

The answer then is to create our JumpLists dynamically.  The best place to do this is in your Application.xaml.vb file.  The New method will be used to instantiate and register the JumpLists, whereas the Startup event will be used to handle arguments passed to the new instance of our application.

Below is a very simple example of JumpLists not too far off from what I ended up going with in my own application. Feel free to leave me comments as to any improvements or changes you would make, or go ahead and fork the gist.

Imports System.Windows.Shell Class Application

Public Sub New()

Dim jl As New JumpList JumpList.SetJumpList(Application.Current, jl)

Dim SaveAs As New JumpTask SaveAs.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly.Location() SaveAs.Title = "Save as..." SaveAs.Arguments = "-saveas" jl.JumpItems.Add(SaveAs)

Dim Configuration As New JumpTask Configuration.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly.Location() Configuration.Title = "Configuration" Configuration.CustomCategory = "Settings" Configuration.Arguments = "-config" jl.JumpItems.Add(Configuration) jl.Apply()

End Sub

Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup

' Handle "Save As" JumpList example If e.Args.Contains("-saveas") Then ' Fancy Code Funtime ' -- Remember, this launches as a new instance - if you don't want that, this end kills it when your done -- End End If

' Handle "Configuration" JumpList example If e.Args.Contains("-config") Then ' I launch a configuration window here, really up to you ' -- Remember, this launches as a new instance - if you don't want that, this end kills it when your done -- End End If

End Sub

End Class



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK