【问题标题】:RichEditBox FontSize C# windows store app unresponsiveRichEditBox FontSize C# windows 商店应用程序无响应
【发布时间】:2013-05-17 04:23:50
【问题描述】:

我正在尝试为用户提供在richeditbox 中输入文本时更改字体大小的选项。 我有以下代码:

    void textBox_GotFocus(object sender, RoutedEventArgs e)
    {
            RichEditBox textBox = sender as RichEditBox;

            ITextSelection selectedText = currentTextBox.Document.Selection;
            if (selectedText != null)
            {
                ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
                charFormatting.Size = (float)textBoxFontSize;
                selectedText.CharacterFormat = charFormatting;
            }                
    }

如果我将输入设备用作鼠标和键盘,则在正常工作时调用此代码。 如果我使用触摸屏并在上述函数中放置一个调试点,此代码也可以工作。

但是如果我使用触摸屏作为输入设备并且代码中没有断点,字体大小会自动变为 10.5,并且永远不会变回来。

我看到其他人也面临类似的问题:

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/771b6374-37da-4cdd-b68c-7b50b939b775

【问题讨论】:

  • 你试过这样的editor.Document.GetRange(0,int.MaxValue).CharacterFormat.Size= aNewFontSize;
  • 嗨@DJKRAZE,从你提到的内容中添加了这段代码:string currentTextBoxText = null; textBox.Document.GetText(TextGetOptions.None, out currentTextBoxText); int textLength = currentTextBoxText.Length - 1; currentTextBox.Document.GetRange(textLength, int.MaxValue).CharacterFormat.Size = (float)textBoxFontSize;,它正在工作。非常感谢。

标签: c# windows-store-apps


【解决方案1】:

感谢 DJ KRAZE 问题彻底解决。 这是响应鼠标键盘和触摸交互的解决方案:

string currentTextBoxText = null; 
textBox.Document.GetText(TextGetOptions.None, out currentTextBoxText); 
int textLength = currentTextBoxText.Length - 1; 
currentTextBox.Document.GetRange(textLength, int.MaxValue).CharacterFormat.Size = (float)textBoxFontSize;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    相关资源
    最近更新 更多