1

我将 ICSharpCode AvalonEdit 源代码编辑 WPF 控件托管到我的 Windows 窗体 C# 应用程序中。我知道以下代码加载了语法高亮定义:

ICSharpCode.AvalonEdit.TextEditor MyEditor = new ICSharpCode.AvalonEdit.TextEditor();
MyEditor.ShowLineNumbers = true;

Stream xshd_stream = File.OpenRead("C:\\Syntax Highlighting\\php.xsdh");
XmlTextReader xshd_reader = new XmlTextReader(xshd_stream);

// Apply the new syntax highlighting definition.
MyEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(
    xshd_reader, ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance
);

xshd_reader.Close();
xshd_stream.Close();

但是,如果在我已经设置了语法高亮定义之后,我不想要任何语法高亮,我只想让它显示为纯文本呢?如何禁用 AvalonEdit 控件中的语法突出显示?

4

1 回答 1

1

你试过MyEditor.SyntaxHighlighting = null吗?
这对我有用:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <avalonEdit:TextEditor SyntaxHighlighting="C#" x:Name="TextEditor">
        public class Foo
        {
        }
    </avalonEdit:TextEditor>

    <Button Grid.Row="1" Content="Reset syntax highlighting" Click="Button_Click" />
</Grid>

代码隐藏:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        TextEditor.SyntaxHighlighting = null; // highlighting disappears
    }
于 2013-01-13T05:33:42.437 回答