Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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# 突出显示WPF文本块中的文本_C#_Wpf_Xaml_Textblock - Fatal编程技术网

C# 突出显示WPF文本块中的文本

C# 突出显示WPF文本块中的文本,c#,wpf,xaml,textblock,C#,Wpf,Xaml,Textblock,我试图突出显示或设置WPF文本块中某些选定文本的背景。 假设我有两个文本文件加载到内存中,完成一个diff,然后想在WPF应用程序中显示。想象一下,循环遍历每一行,然后将文本附加到文本块,并根据已删除、插入或相等的文本更改颜色 for (int i = 0; i < theDiffs.Count; i++) { switch (theDiffs[i].operation) { case Oper

我试图突出显示或设置WPF文本块中某些选定文本的背景。 假设我有两个文本文件加载到内存中,完成一个diff,然后想在WPF应用程序中显示。想象一下,循环遍历每一行,然后将文本附加到文本块,并根据已删除、插入或相等的文本更改颜色

for (int i = 0; i < theDiffs.Count; i++)
        {
            switch (theDiffs[i].operation)
            {
                case Operation.DELETE:
                    // set color to red on Source control version TextBlock
                    break;

                case Operation.INSERT:
                    WorkspaceVersion.AppendText(theDiffs[i].text);
                    // set the background color (or highlight) of appended text to green
                    break;

                case Operation.EQUAL:
                    WorkspaceVersion.AppendText(theDiffs[i].text);
                    // Set the background color (highlight) of appended text to yellow
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
for(int i=0;i
您需要将内联元素附加到。例如(假设“WorkspaceVersion”是一个文本块):


明亮的非常感谢。
case Operation.INSERT:
    // set the background color (or highlight) of appended text to green
    string text = theDiffs[i].text;
    Brush background = Brushes.Green;
    var run = new Run { Text = text, Background = background };
    WorkspaceVersion.Inlines.Add(run);
break;