diff --git a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs index 75889fff..b6ae15fe 100644 --- a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs @@ -10,12 +10,13 @@ namespace v2rayN.Desktop.Views; public partial class MsgView : ReactiveUserControl { - private readonly ScrollViewer _scrollViewer; + private const int MaxLines = 500; public MsgView() { InitializeComponent(); - _scrollViewer = this.FindControl("msgScrollViewer"); + + txtMsg.Options.AllowScrollBelowDocument = false; ViewModel = new MsgViewModel(UpdateViewHandler); @@ -44,12 +45,20 @@ public partial class MsgView : ReactiveUserControl private void ShowMsg(object msg) { - // txtMsg.Text = msg.ToString(); txtMsg.AppendText(msg.ToString()); + + var doc = txtMsg.Document; + if (doc.LineCount > MaxLines) + { + int removeCount = doc.LineCount - MaxLines; + var line = doc.GetLineByNumber(removeCount); + int removeUpTo = line.EndOffset; + doc.Remove(0, removeUpTo); + } + if (togScrollToEnd.IsChecked ?? true) { txtMsg.ScrollToEnd(); - _scrollViewer?.ScrollToEnd(); } }