private void OnGotTextBlockFocus(object sender, RoutedEventArgs e) { if (Context == null) { return; } DesignerView designerView = Context.Services.GetService <DesignerView>(); if (!designerView.IsMultipleSelectionMode) { TextBlock textBlock = sender as TextBlock; bool isInReadOnlyMode = IsReadOnly; if (Context != null) { ReadOnlyState readOnlyState = Context.Items.GetValue <ReadOnlyState>(); isInReadOnlyMode |= readOnlyState.IsReadOnly; } if (null != textBlock) { BlockHeight = textBlock.ActualHeight; BlockHeight = Math.Max(BlockHeight, textBlock.MinHeight); BlockHeight = Math.Min(BlockHeight, textBlock.MaxHeight); BlockWidth = textBlock.ActualWidth; BlockWidth = Math.Max(BlockWidth, textBlock.MinWidth); BlockWidth = Math.Min(BlockWidth, textBlock.MaxWidth); // If it's already an editor, don't need to switch it/reload it (don't create another editor/grid if we don't need to) // Also don't create editor when we are in read only mode if (ContentTemplate.Equals((DataTemplate)FindResource("textblock")) && !isInReadOnlyMode) { if (Context != null) { // Get the ExpressionEditorService ExpressionEditorService1 = Context.Services.GetService <IExpressionEditorService>(); } // If the service exists, use the editor template - else switch to the textbox template if (ExpressionEditorService1 != null) { ContentTemplate = (DataTemplate)FindResource("expressioneditor"); } } } if (!isInReadOnlyMode) { //disable the error icon StartValidator(); EditingState = EditingState.Editing; e.Handled = true; } } }
public override bool Commit(bool isExplicitCommit) { bool committed = false; //only generate and validate the expression when when we don't require explicit commit change //or when the commit is explicit if (!ExplicitCommit || isExplicitCommit) { // Generate and validate the expression. // Get the text from the snapshot and set it to the Text property PreviousText = null; if (ExpressionEditorInstance != null) { PreviousText = Text; Text = ExpressionEditorInstance.GetCommittedText(); } if (Expression != null) { Activity expression = Expression.GetCurrentValue() as Activity; // if expression is null, GetExpressionString will return null PreviousText = ExpressionHelper.GetExpressionString(expression, OwnerActivity); } else { PreviousText = null; } if (EditingTextBox != null) { EditingTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); } // If the Text is null, or equal to the previous value, or changed from null to empty, don't bother generating the expression // We still need to generate the expression when it is changed from other value to EMPTY however - otherwise // the case where you had an expression (valid or invalid), then deleted the whole thing will not be evaluated. if (ShouldGenerateExpression(PreviousText, Text)) { GenerateExpression(); committed = true; } } if (!ContentTemplate.Equals((DataTemplate)FindResource("textblock"))) { ContentTemplate = (DataTemplate)FindResource("textblock"); } return(committed); }
private void DoLostFocus() { KillValidator(); ValidateExpression(this); if (Context != null) { // Unselect if this is the currently selected one. ExpressionSelection current = Context.Items.GetValue <ExpressionSelection>(); if (current != null && current.ModelItem == Expression) { ExpressionSelection emptySelection = new ExpressionSelection(null); Context.Items.SetValue(emptySelection); } } // Generate and validate the expression. // Get the text from the snapshot and set it to the Text property if (ExpressionEditorInstance != null) { ExpressionEditorInstance.ClearSelection(); } bool committed = false; if (!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 || IsIndependentExpression) { 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 (!ContentTemplate.Equals((DataTemplate)FindResource("textblock"))) { ContentTemplate = (DataTemplate)FindResource("textblock"); } } } //raise EditorLostLogical focus - in case when some clients need to do explicit commit RaiseEvent(new RoutedEventArgs(ExpressionTextBox.EditorLostLogicalFocusEvent, this)); }