我正在将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控件中禁用语法突出显示?
发布于 2013-01-13 13:33:42
你试过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
}https://stackoverflow.com/questions/14300932
复制相似问题