Back to Devexpress

ApplicationJumpListService

wpf-18163-mvvm-framework-services-predefined-set-applicationjumplistservice.md

latest8.4 KB
Original Source

ApplicationJumpListService

  • Dec 29, 2021
  • 3 minutes to read

Note

The ApplicationJumpListService doesn’t support .NET/.NET Core.

ApplicationJumpListService allows you to add your own items to the Window’s Jump Lists in accordance with MVVM.
ApplicationJumpListService implements the IApplicationJumpListService interface.

Getting Started

To add custom items to the application’s jump list, add the ApplicationJumpListService to the Interaction.Behaviors collection.

xaml
<dxmvvm:Interaction.Behaviors>
    <dxmvvm:ApplicationJumpListService>
        <dxmvvm:ApplicationJumpTask Title="Internet Explorer" CustomCategory="Internet" Description="Internet Explorer" Command="{Binding RunInternetExplorerCommand}" Icon="{dx:DXImageOffice2013 Image=ViewOnWeb_16x16.png}"/>
    </dxmvvm:ApplicationJumpListService>
</dxmvvm:Interaction.Behaviors>

The ApplicationJumpListService defined in the code snippet above adds a JumpTask , which invokes the View Mode’s RunInternetExplorerCommand to the Internet category in the application’s Jump Lists.

Here is View Model definition.

csharp
[POCOViewModel]
public class MainViewModel {
    protected IApplicationJumpListService ApplicationJumpListService { 
        get { return this.GetService<IApplicationJumpListService>(); } 
    }

    public void RunInternetExplorer() {
        Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe");
    }
}
vb
<POCOViewModel> _
Public Class MainViewModel
    Protected ReadOnly Property ApplicationJumpListService() As IApplicationJumpListService
        Get
            Return Me.GetService(Of IApplicationJumpListService)()
        End Get
    End Property

    Public Sub RunInternetExplorer()
        Process.Start("C:\Program Files\Internet Explorer\iexplore.exe")
    End Sub
End Class

The ApplicationJumpTask class implements the functionality of an individual jump task that can be displayed within the Jump List of the application’s taskbar button.

The most straightforward way to add items to a jump list is to specify ApplicationJumpTask objects directly in XAML. Alternatively, you can use the AddOrReplace method overloads of the ApplicationJumpListService.Items collection to add a jump task in code-behind.

csharp
[POCOViewModel]
public class MainViewModel {
    protected IApplicationJumpListService ApplicationJumpListService { get { return this.GetService<IApplicationJumpListService>(); } }
    ...
    private void RunWindowsMediaPlayer() {
        Process.Start(@"C:\Program Files (x86)\Windows Media Player\wmplayer.exe");
    }
    public void AddItem() {
        ApplicationJumpListService.Items.AddOrReplace(
            "Media", 
            "Windows Media Player", 
            new BitmapImage(new Uri(@"pack://application:,,,/DevExpress.Images.v14.2;component/Office2013/Miscellaneous/Video_16x16.png", UriKind.Absolute)),
            () => RunWindowsMediaPlayer()
        );
        ApplicationJumpListService.Apply();
    }
}
vb
<POCOViewModel> _
Public Class MainViewModel
    Protected ReadOnly Property ApplicationJumpListService() As IApplicationJumpListService
        Get
            Return Me.GetService(Of IApplicationJumpListService)()
        End Get
    End Property

    Public Sub RunInternetExplorer()
        Process.Start("C:\Program Files\Internet Explorer\iexplore.exe")
    End Sub
    Private Sub RunWindowsMediaPlayer()
        Process.Start("C:\Program Files (x86)\Windows Media Player\wmplayer.exe")
    End Sub
    Public Sub AddItem()
        ApplicationJumpListService.Items.AddOrReplace("Media", "Windows Media Player", New BitmapImage(New Uri("pack://application:,,,/DevExpress.Images.v14.2;component/Office2013/Miscellaneous/Video_16x16.png", UriKind.Absolute)), Sub() RunWindowsMediaPlayer())
        ApplicationJumpListService.Apply()
    End Sub
End Class

Note that if you add jump tasks in code manually, you have to execute the ApplicationJumpListService.Apply method, so the application registers and adds the newly added jump tasks to its Jump List.

xaml
<UserControl x:Class="DXSampleApplicationJumpListService.View.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:ViewModel="clr-namespace:DXSampleApplicationJumpListService.ViewModel"
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" 
    DataContext="{dxmvvm:ViewModelSource Type=ViewModel:MainViewModel}">
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:ApplicationJumpListService>
            <dxmvvm:ApplicationJumpTask Title="Internet Explorer" CustomCategory="Internet" Description="Internet Explorer" Command="{Binding RunInternetExplorerCommand}" Icon="{dx:DXImageOffice2013 Image=ViewOnWeb_16x16.png}"/>
        </dxmvvm:ApplicationJumpListService>
    </dxmvvm:Interaction.Behaviors>
    <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Add Window Media Player JumpTask" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding AddItemCommand}"/>
    </Grid>
</UserControl>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;
using DevExpress.Mvvm.DataAnnotations;
using System;
using System.Diagnostics;
using System.Windows.Media.Imaging;
using DevExpress.Xpf.Core;

namespace DXSampleApplicationJumpListService.ViewModel {
    [POCOViewModel]
    public class MainViewModel {
        protected IApplicationJumpListService ApplicationJumpListService { get { return this.GetService<IApplicationJumpListService>(); } }

        public void RunInternetExplorer() {
            Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe");
        }
        private void RunWindowsMediaPlayer() {
            Process.Start(@"C:\Program Files (x86)\Windows Media Player\wmplayer.exe");
        }
        public void AddItem() {
            ApplicationJumpListService.Items.AddOrReplace(
                "Media", 
                "Windows Media Player", 
             new BitmapImage(DXImageHelper.GetImageUri("Images/Miscellaneous/Video_16x16.png")),
                () => RunWindowsMediaPlayer()
            );
            ApplicationJumpListService.Apply();
        }
    }
}
vb
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO
Imports DevExpress.Mvvm.DataAnnotations
Imports System
Imports System.Diagnostics
Imports System.Windows.Media.Imaging
Imports DevExpress.Xpf.Core

Namespace DXSampleApplicationJumpListService.ViewModel
    <POCOViewModel> _
    Public Class MainViewModel
        Protected ReadOnly Property ApplicationJumpListService() As IApplicationJumpListService
            Get
                Return Me.GetService(Of IApplicationJumpListService)()
            End Get
        End Property

        Public Sub RunInternetExplorer()
            Process.Start("C:\Program Files\Internet Explorer\iexplore.exe")
        End Sub
        Private Sub RunWindowsMediaPlayer()
            Process.Start("C:\Program Files (x86)\Windows Media Player\wmplayer.exe")
        End Sub
        Public Sub AddItem()
            ApplicationJumpListService.Items.AddOrReplace("Media", "Windows Media Player", New BitmapImage(DXImageHelper.GetImageUri("Images/Miscellaneous/Video_16x16.png")), Sub() RunWindowsMediaPlayer())
            ApplicationJumpListService.Apply()
        End Sub
    End Class
End Namespace