/// <summary> /// Ends the editing. Events are unwired, and the adorner is removed from the adorner layer. /// </summary> private void EndEditing() { if (null == _adorner) { return; } _adorner.EditingFinished -= EhEditingFinished; // Processing order important here // because setting the Text dependency property can cause updates of the ItemsControl, set this property at the very end // before this, dispose all the plumbing neccessary in edit mode bool validationHasErrors = _adorner.ValidationHasErrors; string textBoxText = _adorner.EditedText; var layer = AdornerLayer.GetAdornerLayer(this); if (null != layer) { layer.Remove(_adorner); } _adorner = null; if (!validationHasErrors) { // update the Text roperty with the new text box value SetValue(TextProperty, textBoxText); } }
/// <summary> /// Begins the editing. Here, the adorner is created and added to the adorner layer, and events to the editing text box are wired. /// </summary> private void BeginEditing() { var layer = AdornerLayer.GetAdornerLayer(this); _adorner = new TextEditingAdorner(this, Text, TextBoxStyle, TextBoxValidationRule); layer.Add(_adorner); _adorner.EditingFinished += EhEditingFinished; }