Expression editing mechanics

This is what happens when you edit an expression in Visual Studio. To simplify things, pretend you started with a blank expression. Here’s what goes on behind the scenes:

  1. When you click on an ExpressionTextBox, an instance of the hostable editor is created.
  2. As you type, you will notice two things:
    • You have IntelliSense, completion and colorization support available immediately.
    • After a short wait, validation is called in the background. If your expression is invalid, the hosted compiler reports the error and the red error icon shows to the right of your expression.
  3. Press Enter. If the ExpressionTextBox is configured in such a way that you can insert new lines by pressing the enter key, then a line commit occurs in the hostable editor. A new line is inserted, pretty listing occurs, and squiggles are added, changed, or removed as necessary.
  4. On lose focus of the ExpressionTextBox, the hostable editor session is destroyed and the display reverts to a TextBlock. If you are on the designer surface or in the property grid, the change to the model item is committed and all ExpressionTextBox controls displaying that same expression are synchronized. However, if you are in a dialog box, the change to the model item is not committed until you click OK. When the model item is committed, we call ActivityValidationServices.Validate and validate the entire workflow.
  5. When you click on the ExpressionTextBox again, pretty listing, colorization, and squiggling occurs before you begin editing.

We destroy the editor when we are done for performance reasons. This is why you see the font switch back and forth. The hostable editor font and keyboard shortcuts are controlled by Text Editor settings, just as in the big IDE, but the workflow designer settings are controlled by the Global environment font.