当前位置: 首页>>代码示例>>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;未经允许,请勿转载。