【发布时间】:2014-07-25 11:04:04
【问题描述】:
我正在开发 Windows 商店应用程序。使用语音合成器将文本块文本转换为语音。要求是根据语音合成输出高亮文本。我在更改文本颜色时遇到问题。只需检查以下代码行即可更改颜色。
代码:
struct SelectionOffsets { internal int Start; internal int End; }
private void highlightWord(int startIndex, int p)
{
try
{
var line = txtContent.Text;
if (p > txtContent.Text.Length)
{
p = txtContent.Text.Length;
}
SelectionOffsets selectionOffsets;
TextPointer contentStart = txtContent.ContentStart;
txtContent.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Colors.Green);
txtContent.IsTextSelectionEnabled = true;
// Find the offset for the starting and ending TextPointers.
selectionOffsets.Start = startIndex;
selectionOffsets.End = p;
txtContent.Select(contentStart.GetPositionAtOffset(selectionOffsets.Start, LogicalDirection.Forward), contentStart.GetPositionAtOffset(selectionOffsets.End, LogicalDirection.Forward));
var s = txtContent.SelectedText;
}
catch(Exception ex)
{
}
}
但它没有反映在 GUI 上。 我还尝试触发文本框样式。但无法在 xaml 中获取标记。 谁能帮我??任何帮助表示赞赏。提前致谢。
【问题讨论】:
-
该属性只是获取或设置用于突出显示选定文本的画笔...它不选择任何文本。您应该使用
TextBox.Selectmethod 来选择文本。 -
我用过,只是这里没有贴代码。我直截了当地说,申请
selectionHighlightColor没有用。 -
它对我来说很好,所以除非你能提供一些代码来证明你的问题,否则这个问题可能很快就会被社区关闭。
-
如果你只是打电话给
txtContent.Select(0, txtContent.Text.Length);呢?
标签: c# xaml windows-phone-8 windows-phone-8.1