添加项目文件。
This commit is contained in:
85
WpfApp/MainWindow.xaml.cs
Normal file
85
WpfApp/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
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.Controls;
|
||||
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;
|
||||
|
||||
using Wpf.Ui.Extend.Controls;
|
||||
|
||||
namespace WpfApp
|
||||
{
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MainWindow : FluentWindowEx
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
DataContext = new MainViewModel();
|
||||
InitializeComponent();
|
||||
|
||||
// 创建并添加自定义的 TraceListener
|
||||
var textBoxListener = new TextBoxTraceListener(DebugTextBox);
|
||||
Debug.Listeners.Add(textBoxListener);
|
||||
|
||||
Debug.WriteLine("这是一个调试输出示例。");
|
||||
}
|
||||
//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)
|
||||
{
|
||||
_textBox = textBox;
|
||||
}
|
||||
|
||||
public override void Write(string message)
|
||||
{
|
||||
AppendText(message);
|
||||
}
|
||||
|
||||
public override void WriteLine(string message)
|
||||
{
|
||||
AppendText(message + Environment.NewLine);
|
||||
}
|
||||
|
||||
private void AppendText(string message)
|
||||
{
|
||||
if (_textBox.Dispatcher.CheckAccess())
|
||||
{
|
||||
_textBox.AppendText(message);
|
||||
_textBox.ScrollToEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
_textBox.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_textBox.AppendText(message);
|
||||
_textBox.ScrollToEnd();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user