protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            if (this.Context != null)
            {
                ExpressionSelection expressionSelection = new ExpressionSelection(this.Expression);
                this.Context.Items.SetValue(expressionSelection);
            }
        }
        private void DoLostFocus()
        {
            KillValidator();

            ValidateExpression(this);

            if (this.Context != null)
            {   // Unselect if this is the currently selected one.
                ExpressionSelection current = this.Context.Items.GetValue<ExpressionSelection>();
                if (current != null && current.ModelItem == this.Expression)
                {
                    ExpressionSelection emptySelection = new ExpressionSelection(null);
                    this.Context.Items.SetValue(emptySelection);
                }
            }

            // Generate and validate the expression.
            // Get the text from the snapshot and set it to the Text property
            if (this.expressionEditorInstance != null)
            {
                this.expressionEditorInstance.ClearSelection();
            }

            bool committed = false;
            if (!this.ExplicitCommit)
            {
                //commit change and let the commit change code do the revert
                committed = Commit(false);

                //reset the error icon if we didn't get to set it in the commit
                if (!committed || this.IsIndependentExpression)
                {
                    this.EditingState = EditingState.Idle;
                    // Switch the control back to a textbox -
                    // but give it the text from the editor (textbox should be bound to the Text property, so should
                    // automatically be filled with the correct text, from when we set the Text property earlier)
                    if (!this.ContentTemplate.Equals((DataTemplate)FindResource("textblock")))
                    {
                        this.ContentTemplate = (DataTemplate)FindResource("textblock");
                    }
                }
            }

            //raise EditorLostLogical focus - in case when some clients need to do explicit commit
            this.RaiseEvent(new RoutedEventArgs(ExpressionTextBox.EditorLostLogicalFocusEvent, this));
        }