我使用DanielGrünwald的BraceFoldingStrategy:
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
List<NewFolding> newFoldings = new List<NewFolding>();
Stack<int> startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = this.OpeningBrace;
char closingBrace = this.ClosingBrace;
for (int i = 0; i < document.TextLength; i++) {
char c = document.GetCharAt(i);
if (c == openingBrace) {
startOffsets.Push(i);
} else if (c == closingBrace && startOffsets.Count > 0) {
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset) …Run Code Online (Sandbox Code Playgroud) 我无法在我的AvalonEdit TextEditor中插入一个字符.
void editor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
{
if (e.Text == "{" || e.Text == "(" || e.Text == "[" || e.Text == "\"" || e.Text == "\'")
{
switch (e.Text)
{
case "{":
int i = editor.TextArea.Caret.Offset;
editor.Text.Insert(i, "}");
break;
case "(":
editor.Text.Insert(editor.CaretOffset, ")");
break;
case "[":
editor.Text.Insert(editor.CaretOffset, "]");
break;
case "\"":
editor.Text.Insert(editor.CaretOffset, "\"");
break;
case "\'":
editor.Text.Insert(editor.CaretOffset, "\'");
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不起作用.请帮我.
什么是在AvalonEdit控件中只读取某些行的强大方法?允许用户更改C#或VB模板文件中的某些方法体,但不允许其他任何方法体.当用户添加或删除行时,每行的只读状态需要保持不变,即编辑内容下方的只读块需要相应地上下移动.
我在winforms上的WPFHost中使用AvalonEdit.
我在AvalonEdit TextEditor滚动到特定行时遇到了很多麻烦.该ScrollTo()行为是简单地滚动,直到该行是在取景当中.我尝试过在互联网上发现的许多不同的方法,所以就像获得偏移一样
double visualTop = textEditor.TextArea.TextView.GetVisualTopByDocumentLine(line);
Run Code Online (Sandbox Code Playgroud)
但每个人都有自己的问题.例如,在上面的行中我得到了例外TextView.VisualLines.
有人尝试过按缩进级别创建FoldingStrategy吗?就像用于python的编程语言一样。
BraceFoldingStrategy没问题,因为您有固定的开始和结束标签。是否有人想为制表符缩进创建此符号?
我正在尝试使在后面的代码中定义的特定可见行(例如 line152)成为 TextView 上的第一条可见行。另外,我希望突出显示这一行。到目前为止,我已经实施了以下解决方案,没有缺乏:
textEditor.ScrollTo(myLine, 0); // Setting the current line Visible (e.g. line152) in TextView
int firstLine = textEditor.TextArea.TextView.GetDocumentLineByVisualTop(textEditor.TextArea.TextView.ScrollOffset.Y).LineNumber; // This is actual top visible line of current TextView ((e.g. line130)
textEditor.ScrollTo(firstLine - myLine, 0); //Which is not working
Run Code Online (Sandbox Code Playgroud)
为了突出显示这一行,我发现了一个 Draw() 函数,但不确定如何调用它:
public void Draw(TextView textView, DrawingContext drawingContext)
{
textView.EnsureVisualLines();
var line = textEditor.Document.GetLineByOffset(textEditor.CaretOffset);
var segment = new TextSegment { StartOffset = line.Offset, EndOffset = line.EndOffset };
foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, segment))
{
drawingContext.DrawRoundedRectangle(
new SolidColorBrush(Color.FromArgb(20, 0xff, 0xff, …Run Code Online (Sandbox Code Playgroud) avalonedit ×6
c# ×5
wpf ×2
avalondock ×1
icsharpcode ×1
python ×1
readonly ×1
scroll ×1
text ×1