How to: Use the Expression Editor
The Expression Editor is a Windows Workflow Designer control that is used in many workflow activities as a means of entering and evaluating these expressions. The Expression Editor provides a full-fledged IDE editing experience including IntelliSense, colorization, ParamInfo, error squiggles, among other features. The compiler validates the expression after it is entered. If the expression is invalid, an error icon is displayed. The editor can also be opened as an Expression Editor dialog box.
Expressions are literal values or Visual Basic code bound to arguments or properties. They contain value elements (e.g. variables, constants, literals, properties) that are combined with operations to yield a new value. Expressions are written using VB.NET syntax even if the application is in a program using C#. This means capitalization does not matter, comparison is performed using a single equals (“=”) sign instead of (“==”), the Boolean operators are the words "and" and "or" instead of the symbols "&&" and "||", and Nothing is used instead of null. For more information about expressions and operators in Visual Basic and for some samples, see Operators and Expressions in Visual Basic.
The Expression Editor behaves as follows:
If the focus is not on the Expression Editor, it looks like a regular TextBlock control.
Once the focus is on the Expression Editor, it looks and behaves like the Expression Editor control. After it loses focus, the it looks like a regular TextBlock again.
If you focus on the Expression Editor in a rehosted workflow designer, then it behaves like a TextBox. When focus is lost in the rehosted workflow designer, the Expression Editor looks like a regular TextBlock again.
|IntelliSense for the Expression Editor is available only inside of Visual Studio 2010. In both the Visual Studio 2010 and the rehosted scenarios, the compiler validates the expression after it is entered and the expression editor displays an error icon if the expression is invalid.|
Using the Expression editor
In Visual Studio 2010, open a new or existing workflow project.
Add, for example, the Assign activity to your workflow.
Note: Multiple workflow activities have expression editors. Expression TextBlocks also appear in the variable designer, argument designer, and the dynamic argument designer. The Assign activity is used as an example.
Click the left expression editor in the activity designer for the Assign activity.
The grey watermark strings <To> and <Enter a VB Expression> are the default text strings for expression editors in the Assign activity.
Enter your expression. If you enter a string, make sure to put quotation marks around the string. If you choose to bind the expression argument to a variable, leave the quotation marks off.
When you are done, select a region or area outside of the Expression Editor to shift the focus to another part of the designer. This will cause the compiler to validate the expression as described previously.
An Alternative way to enter/edit an expression is to click the ellipsis next to the property name in the property grid. This will open the Expression Editor as dialog box.