alielie
2025-03-11 2e54b439c64e0adbb7e010243c1f33aa5fc5f503
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using HMI.Base;
using Panuon.WPF.UI;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
 
namespace WPFProject
{
    /// <summary>
    /// LoadingWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoadingWindow : WindowX
    {
 
        private string consoleText = "";
 
        public string ConsoleText
        {
            get { return consoleText; }
            set { Set(ref consoleText, value); }
        }
 
        public LoadingWindow()
        {
            DataContext = this;
            InitializeComponent();
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }
        private void Loader_LoadMessageAppend(object sender, string e)
        {
            Add(e);
        }
 
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PanuonWindow window = new PanuonWindow();
            window.Show();
            this.Close();
        }
 
        private void WindowX_ContentRendered(object sender, System.EventArgs e)
        {
            PluginLoader loader = PluginLoader.GetLoader();
            loader.LoadMessageAppend += Loader_LoadMessageAppend;
            loader.Loaded += Loader_Loaded;
            Task.Run(() =>
            {
                loader.LoadMenuAndPlugin(Dispatcher);
                //
            });
        }
 
        private void Loader_Loaded(object sender, EventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                Button_Click(null, null);
            });
        }
 
        public void Add(string text)
        {
            string t = string.Format("{0:G}", DateTime.Now);
            Run run = new Run();
            run.Text = t + " 信息:" + text;
            //run.Foreground = new Brush();
 
            Paragraph paragraph = new Paragraph(run) {
                LineHeight =1
            };
            //rtxtLog.Document.Blocks.InsertAfter(); ;
            //插入到最前面
            Console.Document.Blocks.InsertAfter(Console.Document.Blocks.LastBlock, paragraph);
            //也可以插入到最后面
            //rtxtLog.Document.Blocks.Add(paragraph);
 
            // 滚动至最后行
            //rtxtLog.ScrollToEnd();
            //Console.ScrollToHome();
            Console.ScrollToEnd();
            // 删除
            //if (Console.Document.Blocks.Count > 10000)
            //{
            //    for (int i = 1000; i < Console.Document.Blocks.Count; i++)
            //    {
            //        _ = Console.Document.Blocks.Remove(Console.Document.Blocks.FirstBlock);
            //    }
            //}
 
        }
    }
}