优化更新代码,添加界面功能并整合
This commit is contained in:
@@ -6,7 +6,6 @@ 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;
|
||||
@@ -16,70 +15,70 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using Wpf.Ui.Extend.Controls;
|
||||
using WPFluent.Controls;
|
||||
using TextBox = System.Windows.Controls.TextBox;
|
||||
|
||||
namespace WpfApp
|
||||
namespace WpfApp;
|
||||
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MainWindow : FluentWindowEx
|
||||
{
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MainWindow : FluentWindowEx
|
||||
public MainWindow()
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
DataContext = new MainViewModel();
|
||||
InitializeComponent();
|
||||
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());
|
||||
//}
|
||||
// 创建并添加自定义的 TraceListener
|
||||
var textBoxListener = new TextBoxTraceListener(DebugTextBox);
|
||||
Debug.Listeners.Add(textBoxListener);
|
||||
|
||||
Debug.WriteLine("这是一个调试输出示例。");
|
||||
}
|
||||
public class TextBoxTraceListener : TraceListener
|
||||
//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)
|
||||
{
|
||||
private TextBox _textBox;
|
||||
_textBox = textBox;
|
||||
}
|
||||
|
||||
public TextBoxTraceListener(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 = textBox;
|
||||
_textBox.AppendText(message);
|
||||
_textBox.ScrollToEnd();
|
||||
}
|
||||
|
||||
public override void Write(string message)
|
||||
else
|
||||
{
|
||||
AppendText(message);
|
||||
}
|
||||
|
||||
public override void WriteLine(string message)
|
||||
{
|
||||
AppendText(message + Environment.NewLine);
|
||||
}
|
||||
|
||||
private void AppendText(string message)
|
||||
{
|
||||
if (_textBox.Dispatcher.CheckAccess())
|
||||
_textBox.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_textBox.AppendText(message);
|
||||
_textBox.ScrollToEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
_textBox.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_textBox.AppendText(message);
|
||||
_textBox.ScrollToEnd();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user