Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在windows应用商店应用程序中搜索文本_C#_Windows Store Apps - Fatal编程技术网

C# 在windows应用商店应用程序中搜索文本

C# 在windows应用商店应用程序中搜索文本,c#,windows-store-apps,C#,Windows Store Apps,我需要在一些文本框(或其他控件)中进行搜索,但我找不到好的解决方案 为了更清楚,我有一个文本框,当我在其中键入文本时,我需要突出显示其他控件中的文本 在winform应用程序中,我为此编写代码,并使用RichTextBox,这不是什么大问题 但在windows应用商店中,我没有RichTextBox,这里有RichTextBlock和RichEditBox,使用这些控件我找不到搜索文本的方法 这可能吗?也许我可以使用一些外部图书馆? 请提供帮助和帮助。您可以使用文本框(用于输入)和文本块(用于突

我需要在一些文本框(或其他控件)中进行搜索,但我找不到好的解决方案

为了更清楚,我有一个文本框,当我在其中键入文本时,我需要突出显示其他
控件中的文本

在winform应用程序中,我为此编写代码,并使用
RichTextBox
,这不是什么大问题

但在windows应用商店中,我没有
RichTextBox
,这里有
RichTextBlock
RichEditBox
,使用这些控件我找不到搜索文本的方法

这可能吗?也许我可以使用一些外部图书馆? 请提供帮助和帮助。

您可以使用文本框(用于输入)和文本块(用于突出显示内容)。 TextBox控件在每次按下键时都会引发一个名为TextChanged的事件。TextBlock中有一个名为Inlines的属性,您可以在其中放置一些文本元素(如Span、Run等)。 您的TextBlock可以这样声明:

<TextBlock x:Name="MyTb">
    Lorem ipsum sit amet
</TextBlock>
<TextBox TextChanged="TextBox_TextChanged" />
var txtToHighlight = (sender as TextBox)?.Text;
if (!string.IsNullOrWhiteSpace(txtToHighlight))
{
    var tb = MyTb;
    var currentTxt = tb.Text;
    tb.Inlines.Clear();
    var ix = currentTxt.IndexOf(txtToHighlight);
    if (ix >= 0)
    {
        var highlightContent = new Span { Foreground = new SolidColorBrush(Colors.Red) };
        highlightContent.Inlines.Add(new Run { Text = currentTxt.Substring(ix, txtToHighlight.Length) });

        tb.Inlines.Add(new Run { Text = currentTxt.Substring(0, ix) });
        tb.Inlines.Add(highlightContent);
        tb.Inlines.Add(new Run { Text = currentTxt.Substring(ix + txtToHighlight.Length) });
    }
    else
    {
        tb.Text = currentTxt;
    }
}