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:
- 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
- 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:
- Implement the IExpressionEditorService interface. The IExpressionEditorService interface manages the creation and destruction of expression editors.
- Implement the IExpressionEditorInstance interface. This interface will contain the guts of your expression editing UI.
- 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()}
};
designer.Load(root);
Grid.SetColumn(designer.View, 0);
// Create ExpressionEditorService
this.expressionEditorService = new MyEditorService();
designer.Context.Services.Publish<IExpressionEditorService>(this.expressionEditorService);
MyGrid.Children.Add(designer.View);
}
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.
Comments
- Anonymous
November 11, 2009
Thanks Cathy and Eric for sharing this sample which is very useful to understand the service logic required to inject custom expression editors, which is one of the aspects I was looking for in my re-hosting.Adriano - Anonymous
December 20, 2009
Thanks! I hope there will be more WF4 articles in the future! - Anonymous
March 01, 2010
hi i´m trying to implement Intellisense on the new rehosting wf 4.0.great example this one to understand the concept but do you have more articles with this subject ou examples...thnaksRui M. - Anonymous
April 06, 2010
Your article is too short and lacks brief explanations. Please add extra notes or samples in further writings. - Anonymous
September 03, 2010
Look here for an example with intellisense:social.msdn.microsoft.com/.../07f89fc0-81ff-4e85-a974-013b15b62f50 - Anonymous
April 13, 2011
The comment has been removed - Anonymous
December 22, 2011
Did anybody succeed to make this working? - Anonymous
June 14, 2012
Was anyone able to use the sample code to work? - Anonymous
August 26, 2013
The comment has been removed