-
Notifications
You must be signed in to change notification settings - Fork 25
Tasks Service
The tasks service provides information regarding currently open windows, and allows basic window management.
There are a few objects involved with using the tasks service:
-
Tasks
provides theGroupedWindows
collection view and methods to manage the tasks service lifecycle. -
TasksService
provides the Windows hook functionality to populate window data. -
ApplicationWindow
objects represent each individual window.
If you are using the ShellManager
to instantiate ManagedShell, the lifecycle of the tasks service is managed for you. However, you can customize this behavior by passing a ShellConfig
object to the ShellManager
constructor to modify settings:
// Initialize the default configuration.
ShellConfig config = ShellManager.DefaultShellConfig;
// Customize tasks service options.
config.EnableTasksService = true; // controls whether the tasks objects are instantiated in ShellManager, true by default
config.AutoStartTasksService = false; // controls whether the tasks service is started as part of ShellManager instantiation, true by default
config.TaskIconSize = IconSize.Medium; // sets the size of window icon to fetch, small (16pt) by default
// Initialize the shell manager.
ShellManager _shellManager = new ShellManager(config);
// Initialize the tasks service, since we disabled auto-start above.
_shellManager.Tasks.Initialize();
The tasks service can be used without ShellManager
management, if desired.
// Instantiate service.
TasksService tasksService = new TasksService(IconSize.Small);
Tasks tasks = new Tasks(tasksService);
// Start the service.
tasks.Initialize();
// Access the window listing.
MyTaskbarItemsControl.ItemsSource = tasks.GroupedWindows;
// Dispose of the service and icons.
IconHelper.DisposeIml();
tasks.Dispose();
The tasks service supports defining custom groupings for windows, by implementing the ITaskCategoryProvider
interface. This interface defines two methods:
-
string GetCategory(ApplicationWindow window)
- The implementation should return a string value representing the category of the passedwindow
. -
void SetCategoryChangeDelegate(TaskCategoryChangeDelegate changeDelegate)
- The implementation should maintain a reference tochangeDelegate
and call it whenever task category data changes. When called, the tasks service will query for each window's category using the aboveGetCategory
method.
To enable task categorization, perform a custom initialization of the Tasks
object, passing in your custom ITaskCategoryProvider
implementation:
// Instantiate service.
TasksService tasksService = new TasksService(IconSize.Small);
Tasks tasks = new Tasks(tasksService);
// Instantiate the task category provider.
MyTaskCategoryProvider categoryProvider = new MyTaskCategoryProvider();
// Start the service with the custom category provider.
tasks.Initialize(categoryProvider);
The tasks service provides window management functionality essential for shell replacements, via methods on each ApplicationWindow
object in the GroupedWindows
collection:
private void DoStuffToWindow(ApplicationWindow window)
{
// Select window
window.BringToFront();
// Minimize window
window.Minimize();
// Maximize window
window.Maximize();
// Restore window
window.Restore();
// Close window
window.Close();
}