109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
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;
|
|
|
|
using WpfApp;
|
|
|
|
using WPFluent.Appearance;
|
|
using WPFluent.Controls;
|
|
|
|
using TextBox = System.Windows.Controls.TextBox;
|
|
|
|
namespace WPFAppTest;
|
|
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : FluentWindowEx
|
|
{
|
|
public MainWindow()
|
|
{
|
|
DataContext = new MainViewModel();
|
|
InitializeComponent();
|
|
//var res = Resources;
|
|
// 创建并添加自定义的 TraceListener
|
|
//var textBoxListener = new TextBoxTraceListener(DebugTextBox);
|
|
//Debug.Listeners.Add(textBoxListener);
|
|
|
|
//Debug.WriteLine("这是一个调试输出示例。");
|
|
App.FetchResources(Resources);
|
|
ApplicationThemeManager.Apply(this);
|
|
ApplicationThemeManager.Changed -= ApplicationThemeManager_Changed;
|
|
ApplicationThemeManager.Changed += ApplicationThemeManager_Changed;
|
|
App.FetchResources(Resources);
|
|
|
|
}
|
|
//public static BitmapSource ToBitmapSource(Bitmap bitmap)
|
|
//{
|
|
// if (bitmap == null)
|
|
// {
|
|
// return null;
|
|
// }
|
|
// return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
|
//}
|
|
private void ApplicationThemeManager_Changed(ApplicationTheme currentApplicationTheme, System.Windows.Media.Color systemAccent)
|
|
{
|
|
ApplicationThemeManager.Apply(this);
|
|
}
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ApplicationThemeManager.GetAppTheme() == ApplicationTheme.Light)
|
|
{
|
|
ApplicationThemeManager.Apply(ApplicationTheme.Dark);
|
|
}
|
|
else
|
|
{
|
|
ApplicationThemeManager.Apply(ApplicationTheme.Light);
|
|
}
|
|
}
|
|
}
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
} |