Home > Components > DXCore Components – ContextPicker

DXCore Components – ContextPicker

September 25th, 2010

The ContextPicker component allows users to specify sophisticated context expressions. It is populated from the context providers registered in the DXCore. For example, take a look at the Shortcuts options page and the context picker used on this page where you can bind a context for any shortcut available.

Here it is:

DXCore Context Picker preview

If we wanted to limit a shortcut to a more constrained context, we could specify those constraints in the context picker. For example, if we wanted this binding to work only when the code editor had focus, we would give the “Focus\Documents\Source\Code Editor context a green check, which means this condition (context) must be satisfied (the editor must have focus).

Note that if you click the condition a second time, the green check will turn into a red X, indicating that the condition must be false, in order for the binding to be valid. Clicking the condition a third time will cycle it back to an empty box, which means the context is ignored. If you clear all entries in the context picker, you’ll have a context that will always be satisfied. It is possible to combine contexts in very sophisticated ways, so you can precisely define the state in which the shortcut binding is allowed to function.

The configured sophisticated context is shown in a human readable format under the “Use:” label, e.g.:

Use: IsWPF and Code Editor but not Debug Mode

You can drop the ContextPicker onto your plug-in design surface from the “DXCore” category of Visual Studio Toolbox:

DXCore Context Picker Toolbox item

It’s a visual control, so you need to choose it’s location on a form, and tweak its properties and events if needed. The ContextPicker component is located in the “DevExpress.CodeRush.UserControls” assembly. It is derived from the “System.Windows.Forms.UserControl” class:

DXCore Context Picker hierarchy

Here’s a list of properties in alphabetical order, without base type (UserControl) properties:

Property name


ExcludedLegend Legend text for the Excluded state.
FourState If true, there will be 4 checkbox states (ignored, mixed, selected, and excluded). Otherwise, there will be only the first 3 states.
HintDisplayTime Defines display time for the hint.
HintWindowWidth Defines the width of the hint window.
IgnoredLegend Legend text for the Ignored state.
LegendBackground Legend background color.
LegendFont Legend text font.
MixedLegend Legend text for the Mixed state.
RootContext If not empty, specifies a comma-separated list of contexts that should be included in the tree.  For instance, if RootContext = “Editor”, only nodes that start with “Editor\” will be included in the tree.
SelectedLegend Legend text for the Selected state.
ShowHint Determines if ContextPicker should display the hint for the context descriptions.
ShowLegend Determines the visibility of the legend.


Event name Description
CheckStateChanged Occurs when a user changes the state of one of the contexts inside the context picker.

To use the ContextPicker you should do the following:

1. Populate it with the registered and available contexts when it is loaded/shown like this:

CodeRush.Context.PopulateContextPicker(ContextPickerInstance, LanguageID);

2. Call the ContextPickerInstance.SetData() method to set the specified context data from a context-holding object (e.g. Template from the “DevExpress.CodeRush.Core” assembly) to the context picker.
3. Call the ContextPickerInstance.GetData() method to get the specified context data from the context picker to the context-holding object
4. Handle the CheckStateChanged event to apply user context changes to context-holding objects.

Products: DXCore
Versions: 11.1 and up
VS IDEs: any
Updated: Aug/30/2010
ID: D012

Similar Posts: