public override void OnApplyTemplate() { base.OnApplyTemplate(); _editorText = GetTemplateChild("PART_EditorText") as MultiLineTextEditor; if (_editorText != null) { _editorText.LostFocus += EditorTextOnLostFocus; _editorText.GotFocus += EditorTextOnGotFocus; } }
private void OnTextContentPropertyChanged(DependencyPropertyChangedEventArgs e) { string value = e.NewValue as string; _editorText = GetTemplateChild("PART_EditorText") as MultiLineTextEditor; if (_editorText != null) { _editorText.Text = value; } _currentDataArea = value; }
void StrengthTrainingDataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e) { if (!GuiState.Default.SmartEditingDataGrid) { return; } ContentPresenter cp = e.EditingElement as ContentPresenter; if (cp != null) { UIElement destinationTextBox = VisualTreeHelper.GetChild(cp, 0) as UIElement; if (destinationTextBox is ContentPresenter) { destinationTextBox = VisualTreeHelper.GetChild(destinationTextBox, 0) as UIElement; } if (destinationTextBox != null) { destinationTextBox.Focus(); } if (destinationTextBox is Panel) { destinationTextBox = UIHelper.GetVisualChild <TextBox>(destinationTextBox); } MultiLineTextEditor multi = destinationTextBox as MultiLineTextEditor; if (multi != null) { multi.IsOpen = true; } TextBox tb = destinationTextBox as TextBox; if (tb != null) { tb.SelectAll(); tb.Focus(); } } }
private void EditorTextOnLostFocus(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(_previousDataArea) && (string.IsNullOrEmpty(this._currentDataArea))) { return; } if (_editorText == null) { _editorText = GetTemplateChild("PART_EditorText") as MultiLineTextEditor; } if (_editorText == null) { return; } // ok _dataAreaChanged = _previousDataArea != _editorText.Text; if (_dataAreaChanged) { _previousDataArea = _currentDataArea; _currentDataArea = _editorText.Text; if (_editorText.Text != null) { DataAreaFieldEventsArgs ev = new DataAreaFieldEventsArgs(DataAreaChangedEvent); ev.FieldData = _editorText.Text; ComponentFiller filler = new ComponentFiller(); var dataObject = ControlExt.GetDataSource(this); if (dataObject == null) { dataObject = DataSource; } if (!string.IsNullOrEmpty(DataSourcePath)) { var path = DataSourcePath; if (string.IsNullOrEmpty(DataSourcePath)) { path = ControlExt.GetDataSourcePath(this); } filler.FillDataObject(_editorText.Text, path, ref dataObject); DataSource = dataObject; IDictionary <string, object> valueDictionary = CreateDictionary(dataObject, _editorText.Text, _previousDataArea); ev.ChangedValuesObjects = valueDictionary; if (ItemChangedCommand != null) { ICommand ex = ItemChangedCommand; if (ex.CanExecute(valueDictionary)) { ex.Execute(valueDictionary); } } RaiseEvent(ev); _dataAreaChanged = false; } else { IDictionary <string, object> valueDictionary = CreateDictionary(dataObject, _editorText.Text, _previousDataArea); if (ItemChangedCommand != null) { ICommand ex = ItemChangedCommand; if (ex.CanExecute(valueDictionary)) { ex.Execute(valueDictionary); } } } } } }