當前位置: 首頁>>代碼示例>>C#>>正文


C# TextEditor.SetSelectedText方法代碼示例

本文整理匯總了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);
            } 
        }
開發者ID:sjyanxin,項目名稱:WPFSource,代碼行數:74,代碼來源:TextEditorTyping.cs


注:本文中的System.Windows.Documents.TextEditor.SetSelectedText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。