【发布时间】: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,并且永远不会变回来。
我看到其他人也面临类似的问题:
【问题讨论】:
-
你试过这样的
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