Share via


Tool Architecture

Users interact with content on a designer in a variety of complex ways. For example, users might interact with the design surface by way of clicks, drags, drags with modifier keys, keyboard, or menu interaction. In order to be extensible, a designer must supply a foundation for handling all these types of user interaction. The Windows Presentation Foundation (WPF) Designer for Visual Studio provides a flexible but structured input system that is extensible and consistent. The user model for tool architecture consists of commands, tasks, and tools.

Commands

A Command is a unique identifier that represents some behavior. An example is the Cut command, which identifies the process of cutting text or an object, and adding it to the Clipboard. While the code that implements the command might be different from application to application, or even within an application, the command remains constant. All commands implement the ICommand interface.

In addition to the command itself, there are two other things that you need to make a command work. First, a command requires some kind of user input (called a gesture) that triggers the command. For example, the CTRL+X keystroke combination or the selection from a menu might be a gesture that triggers a command. Second, a command requires some kind of code implementation that is executed when the command is invoked.

WPF provides a built-in implementation of the ICommand interface called RoutedCommand which passes information about user input to the designated command handlers. The WPF Designer provides another command type called ToolCommand, which expands the amount of information about the state of the designer that is passed to the command handler's EventArgs type.

Tasks

A Task is an object that represents an actual task that might occur in the designer. For example, dragging an item on the designer might be represented by a Task object. A Task holds three collections:

  1. A collection of input bindings that describe the kinds of user input handled by the task. For example, bindings that represent keystroke combinations or mouse gestures.

  2. A collection of command bindings that provide implementations for standard WPF routed commands.

  3. A collection of tool command bindings that provide implementation for the WPF Designer tool commands.

For example, the previously mentioned Task object that represents dragging an item on the designer might contain commands that represent mouse down, mouse move, and mouse up. The Task object might also contain input bindings that bind input gestures to each of those commands.

Tools

A Tool is a class that is used to process user input. All user input comes into the designer as one or more input events, carrying data that represents the input gesture used and other information about the state of the designer. The input event is routed to the currently active Tool object, which converts the input data to input bindings. If a binding is found for the indicated input gesture, the command within the binding is executed.

The Tool object is used to represent the global mode of the designer. For example, if the user is selecting components on the design surface, that mode is enabled because the current tool offers tasks that provide the collections of input bindings and commands that bind particular input gestures to particular commands that enable those tasks. If the user were creating a new control, the active tool would be different and would offer a different set of bindings that might allow the user to use the same gestures, but bind them to different commands.

See Also

Concepts

User Input and Presentation Architecture

WPF Designer Extensibility Architecture

Reference

Tool

Task

ToolCommand

ICommand