本文整理汇总了C#中System.Windows.Documents.TextEditor.SetSelectedText方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.SetSelectedText方法的具体用法?C# TextEditor.SetSelectedText怎么用?C# TextEditor.SetSelectedText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextEditor
的用法示例。
在下文中一共展示了TextEditor.SetSelectedText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTextInput
// ......................................................
//
// Handling Text Input
//
// ......................................................
/// <summary>
/// This is a single method used to insert user input characters.
/// It takes care of typing undo, springload formatting, overtype mode etc.
/// </summary>
/// <param name="This"></param>
/// <param name="textData">
/// Text to insert.
/// </param>
/// <param name="isInsertKeyToggled">
/// Reflects a state of Insert key at the moment of textData input.
/// </param>
/// <param name="acceptControlCharacters">
/// True indicates that control characters like '\t' or '\r' etc. can be inserted.
/// False means that all control characters are filtered out.
/// </param>
private static void DoTextInput(TextEditor This, string textData, bool isInsertKeyToggled, bool acceptControlCharacters)
{
// Hide the mouse cursor on user input.
HideCursor(This);
// Remove control characters. Note that this is not included into _FilterText,
// because we want such kind of filtering only for real input,
// not for copy/paste.
if (!acceptControlCharacters)
{
for (int i = 0; i < textData.Length; i++)
{
if (Char.IsControl(textData[i]))
{
textData = textData.Remove(i--, 1); // decrement i to compensate for character removal
}
}
}
string filteredText = This._FilterText(textData, This.Selection);
if (filteredText.Length == 0)
{
return;
}
TextEditorTyping.OpenTypingUndoUnit(This);
UndoCloseAction closeAction = UndoCloseAction.Rollback;
try
{
using (This.Selection.DeclareChangeBlock())
{
This.Selection.ApplyTypingHeuristics(This.AllowOvertype && This._OvertypeMode && filteredText != "\t");
This.SetSelectedText(filteredText, InputLanguageManager.Current.CurrentInputLanguage);
// Create caret position normalized backward to keep formatting of a character just typed
ITextPointer caretPosition = This.Selection.End.CreatePointer(LogicalDirection.Backward);
// Set selection at the end of input content
This.Selection.SetCaretToPosition(caretPosition, LogicalDirection.Backward, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/true);
// Note: Using explicit backward orientation we keep formatting with
// a previous character during typing.
closeAction = UndoCloseAction.Commit;
}
}
finally
{
TextEditorTyping.CloseTypingUndoUnit(This, closeAction);
}
}