private void btnReplaceAll_Click(object sender, RoutedEventArgs e) { int foundCount = 0; this.richTextBox.SuspendUpdateLayout(); this.Document.BeginUpdate(); try { using (DocumentPosition startFindPosition = new DocumentPosition(this.Document.DocumentLayoutBox, true)) { var found = true; while (found) { DocumentTextSearch textSearch = new DocumentTextSearch(this.Document); TextRange find = textSearch.Find(this.GetSearchText(), startFindPosition); found = find != null; if (found) { startFindPosition.MoveToPosition(find.EndPosition); startFindPosition.AnchorToNextFormattingSymbol(); //This is needed to update the current style for editing this.Document.CaretPosition.MoveToPosition(find.StartPosition); find.SetSelection(this.Document); if (this.replaceCallback(this.tbReplaceText.Text)) { foundCount++; } startFindPosition.RemoveAnchorFromNextFormattingSymbol(); startFindPosition.MoveToPosition(this.Document.CaretPosition); } } } } finally { this.Document.EndUpdate(); this.richTextBox.ResumeUpdateLayout(); } RadWindow.Alert(new DialogParameters() { Header = this.Header, Content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_MadeReplacements"), foundCount), Owner = this }); }
private void btnReplaceAll_Click(object sender, RoutedEventArgs e) { int foundCount = 0; this.richTextBox.SuspendUpdateLayout(); this.Document.BeginUpdate(); try { using (DocumentPosition startFindPosition = new DocumentPosition(this.Document.DocumentLayoutBox, true)) { var found = true; while (found) { DocumentTextSearch textSearch = new DocumentTextSearch(this.Document); TextRange find = textSearch.Find(this.GetSearchText(), startFindPosition); found = find != null; if (found) { startFindPosition.MoveToPosition(find.EndPosition); startFindPosition.AnchorToNextFormattingSymbol(); //This is needed to update the current style for editing this.Document.CaretPosition.MoveToPosition(find.StartPosition); find.SetSelection(this.Document); if (this.replaceCallback(this.tbReplaceText.Text)) { foundCount++; } startFindPosition.RemoveAnchorFromNextFormattingSymbol(); } } } } finally { this.Document.EndUpdate(); this.richTextBox.ResumeUpdateLayout(); } RadWindow.Alert(new DialogParameters() { Header = this.Header, Content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_MadeReplacements"), foundCount) }); }