2024-09-22 11:05:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Interop;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
using WPFluent.Controls;
|
|
|
|
|
|
using TextBox = System.Windows.Controls.TextBox;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
namespace WpfApp;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// MainWindow.xaml 的交互逻辑
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class MainWindow : FluentWindowEx
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
2025-02-10 20:53:40 +08:00
|
|
|
|
public MainWindow()
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
2025-02-10 20:53:40 +08:00
|
|
|
|
DataContext = new MainViewModel();
|
|
|
|
|
|
InitializeComponent();
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
// 创建并添加自定义的 TraceListener
|
|
|
|
|
|
var textBoxListener = new TextBoxTraceListener(DebugTextBox);
|
|
|
|
|
|
Debug.Listeners.Add(textBoxListener);
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
Debug.WriteLine("这是一个调试输出示例。");
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
2025-02-10 20:53:40 +08:00
|
|
|
|
//public static BitmapSource ToBitmapSource(Bitmap bitmap)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (bitmap == null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public class TextBoxTraceListener : TraceListener
|
|
|
|
|
|
{
|
|
|
|
|
|
private TextBox _textBox;
|
|
|
|
|
|
|
|
|
|
|
|
public TextBoxTraceListener(TextBox textBox)
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
2025-02-10 20:53:40 +08:00
|
|
|
|
_textBox = textBox;
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
public override void Write(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
AppendText(message);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
public override void WriteLine(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
AppendText(message + Environment.NewLine);
|
|
|
|
|
|
}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
private void AppendText(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_textBox.Dispatcher.CheckAccess())
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
2025-02-10 20:53:40 +08:00
|
|
|
|
_textBox.AppendText(message);
|
|
|
|
|
|
_textBox.ScrollToEnd();
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
2025-02-10 20:53:40 +08:00
|
|
|
|
else
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
2025-02-10 20:53:40 +08:00
|
|
|
|
_textBox.Dispatcher.Invoke(() =>
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
_textBox.AppendText(message);
|
|
|
|
|
|
_textBox.ScrollToEnd();
|
2025-02-10 20:53:40 +08:00
|
|
|
|
});
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-10 20:53:40 +08:00
|
|
|
|
}
|