public void StartEditing() { IsEditing = true; StartCaptureMouse(); EditingText = Text; EditingTextBox.Focus(); EditingTextBox.CaretIndex = EditingTextBox.Text.Length; }
private void InitBindings() { StaticTextBlock.SetBinding(TextBlock.FontSizeProperty, new Binding(nameof(FontSize)) { Source = this, Mode = BindingMode.OneWay }); StaticTextBlock.SetBinding(TextBlock.FontFamilyProperty, new Binding(nameof(FontFamily)) { Source = this, Mode = BindingMode.OneWay }); StaticTextBlock.SetBinding(TextBlock.TextProperty, new Binding(nameof(Text)) { Source = this, Mode = BindingMode.OneWay }); StaticTextBlock.SetBinding(TextBlock.ForegroundProperty, new Binding(nameof(Foreground)) { Source = this, Mode = BindingMode.OneWay }); EditingTextBox.SetBinding(TextBox.FontSizeProperty, new Binding(nameof(FontSize)) { Source = this, Mode = BindingMode.OneWay }); EditingTextBox.SetBinding(TextBox.FontFamilyProperty, new Binding(nameof(FontFamily)) { Source = this, Mode = BindingMode.OneWay }); EditingTextBox.SetBinding(TextBox.TextProperty, new Binding(nameof(EditingText)) { Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); EditingTextBox.SetBinding(TextBox.BackgroundProperty, new Binding(nameof(EditingBackground)) { Source = this, Mode = BindingMode.OneWay }); EditingTextBox.SetBinding(TextBox.ForegroundProperty, new Binding(nameof(EditingForeground)) { Source = this, Mode = BindingMode.OneWay }); EditingTextBox.SetBinding(TextBox.VisibilityProperty, new Binding(nameof(IsEditing)) { Source = this, Mode = BindingMode.OneWay, Converter = new BoolToVisibilityConverter() }); EventArea.SetBinding(Border.IsHitTestVisibleProperty, new Binding(nameof(IsEditing)) { Source = this, Mode = BindingMode.OneWay, Converter = new BoolInvertConverter() }); }
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); }