对于我的项目,我想显示从外部文件获取的 C# 源代码。我想要做的就是解析该文件,并在可能的情况下用语法高亮显示代码。
如果可能的话,我想将我阅读的代码分成各种方法。
我应该从哪里开始?
最佳答案
我推荐 AvalonEdit .它易于设置和使用。示例
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
<avalonEdit:TextEditor Name="textEditor"
Loaded="textEditor_Loaded"
FontFamily="Consolas"
FontSize="10pt"/>
private void textEditor_Loaded(object sender, RoutedEventArgs e)
{
textEditor.Load(@"C:\MainWindow.xaml.cs");
textEditor.SyntaxHighlighting =
HighlightingManager.Instance.GetDefinition("C#");
}
示例输出
关于c# - 如何从外部文件显示 C# 源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4279376/