如何重置ICSharpCode.AvalonEdit语法高亮?

时间:2013-01-13 05:23:20

标签: c# wpf winforms avalonedit icsharpcode

我正在将ICSharpCode AvalonEdit源代码编辑WPF控件托管到我的Windows Forms 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控件中的语法高亮?

1 个答案:

答案 0 :(得分: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
    }