我正在开发windows商店应用程序。利用语音synthesizer.The要求将文本块转换成语音是根据语音合成输出的高亮度文本。在改变文字颜色的同时,我也面临着问题。只需检查下面的代码行即可更改颜色。
代码:
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中获取标记的文本框styling.But提供触发器。有谁可以帮我??任何帮助都是非常感谢的。提前谢谢。
发布于 2014-07-25 17:31:53
在ui元素聚焦之前,选择仍然是不可见的。
因此,尝试在txtContent.Focus()之后调用txtContent.Select()。
https://stackoverflow.com/questions/24954300
复制相似问题