c# - UWP:如何动态选择文本框中最后输入的单词并更改其突出显示颜色?
问题描述
这是我用来获取最后输入的单词的winform代码
string txt = richTextBox1.Text;
string lastWordspace = txt.Substring(txt.LastIndexOf(" ") + 1);
string lastWord = lastWordspace.Substring(lastWordspace.LastIndexOf("\n") + 1);
richTextBox1.SelectionStart = richTextBox1.Text.LastIndexOf(lastWord);
richTextBox1.SelectionLength = lastWord.Length;
richTextBox1.SelectionBackColor = Color.LightCoral;
我想要 UWP 中的相同功能。如何选择文本框中最后输入的单词并使用 c# 动态更改其突出显示颜色?
解决方案
在 UWP 中,对应的RichTextBox
是RichEditBox
.
你可以试试这个:
TestRichEditBox.TextDocument.GetText(Windows.UI.Text.TextGetOptions.None, out string txt);
int lastIndex = txt.Length - 2;
TestRichEditBox.Document.Selection.SetRange(lastIndex, lastIndex + 1);
TestRichEditBox.SelectionHighlightColor = new SolidColorBrush(Colors.LightCoral);
此致。
推荐阅读
- awk - 如何在脚本中使用 awk 命令来保存永久修改
- html - Bootstrap 4.1 中悬停时的下拉子菜单
- javascript - 如何使用 Jasmine 测试 Angular 6 中包装在 ng-container 中的元素?
- vba - 如何为数据透视表选择数据源的动态范围(从活动选择中)
- android - E/libEGL: validate_display:99 错误 3008 (EGL_BAD_DISPLAY)
- c# - 难倒递归解决方案
- azure - 在 Azure 中通过 ARM 模板部署 Windows 和 Linux VM
- r - Plotly - 如何更改直方图颜色?
- python - 此代码如何工作以替换 Python 中前几行中的值
- devise - 使用 Devise 的 Ruby on Rails 两因素身份验证