Implementing a custom expression editor

I’ve seen a few forum posts about providing a richer expression editing experience in a rehosted workflow designer. There are two main scenarios in which you would want to implement your own expression editor:

  1. Work around the rather unfortunate limitation that the hostable editor is not available outside of Visual Studio, so therefore there is no support for IntelliSense in a rehosted application
  2. Simplify the expression editing experience for the business analyst audience, so that analysts are not required to learn VB or deal with VB expressions.

Our intrepid expression editor tester, Eric Wong, put together a small app that demonstrates the process of implementing a custom expression editor. There are three basic steps:

  1. Implement the IExpressionEditorService interface. The IExpressionEditorService interface manages the creation and destruction of expression editors.
  2. Implement the IExpressionEditorInstance interface. This interface will contain the guts of your expression editing UI.
  3. Publish the IExpressionEditorService in your application.

Eric’s app has two projects, a class library that implements the editor service and instance and a WPF application that rehosts the designer and publishes the service. The class library is a proof of concept, and doesn’t do anything terribly interesting (you’ll have to roll your own IntelliSense). The most important part of the example is the code that he uses to publish the service, called MyEditorService. Here it is:

         public void createDesigner()
            WorkflowDesigner designer = new WorkflowDesigner();
            Sequence root = new Sequence()
                Activities = {
                new Assign(),
                new WriteLine()}

            Grid.SetColumn(designer.View, 0);

            // Create ExpressionEditorService
            this.expressionEditorService = new MyEditorService();


You can test out Eric’s app using some of the many keyboard shortcuts associated with IntelliSense commands. For example, Ctrl+J invokes IntelliSense, Ctrl+K, I invokes QuickInfo, etc. Thanks Eric for sharing this out.