| | |
| | | using System; |
| | | using HMI.Base; |
| | | using Panuon.WPF.UI; |
| | | using System; |
| | | using System.Threading.Tasks; |
| | | using System.Windows; |
| | | using HMI.Base; |
| | | using System.Windows.Documents; |
| | | |
| | | namespace WPFProject |
| | | { |
| | | /// <summary> |
| | | /// LoadingWindow.xaml 的交互逻辑 |
| | | /// </summary> |
| | | public partial class LoadingWindow : Window |
| | | 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) |
| | | { |
| | | PluginLoader loader = PluginLoader.GetLoader(); |
| | | loader.LoadMessageAppend += Loader_LoadMessageAppend; |
| | | loader.LoadMenuAndPlugin(); |
| | | Button_Click(null,null); |
| | | } |
| | | |
| | | } |
| | | private void Loader_LoadMessageAppend(object sender, string e) |
| | | { |
| | | this.Dispatcher.BeginInvoke((Action)delegate () |
| | | { |
| | | Console.Text = Console.Text + $"{e}\r\n"; |
| | | }); |
| | | Add(e); |
| | | } |
| | | |
| | | |
| | | private void Button_Click(object sender, RoutedEventArgs e) |
| | | { |
| | |
| | | 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); |
| | | // } |
| | | //} |
| | | |
| | | } |
| | | } |
| | | } |