【问题标题】:Highlighting text according to text to speech synthesis output根据文本到语音合成输出突出显示文本
【发布时间】: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.Select method 来选择文本。
  • 我用过,只是这里没有贴代码。我直截了当地说,申请selectionHighlightColor 没有用。
  • 它对我来说很好,所以除非你能提供一些代码来证明你的问题,否则这个问题可能很快就会被社区关闭。
  • 如果你只是打电话给txtContent.Select(0, txtContent.Text.Length);呢?

标签: c# xaml windows-phone-8 windows-phone-8.1


【解决方案1】:

在 ui 元素获得焦点之前,选择保持不可见。

所以尝试在 txtContent.Select() 之后调用 txtContent.Focus()。

【讨论】:

  • 它给出了相同的结果。及其txtContent.Focus(FocusState value)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-24
  • 1970-01-01
  • 2019-08-13
  • 2020-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多