mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
修复 DpiHelper 在未初始化窗口句柄时获取 DPI 缩放值的问题,现在能正确处理多显示器场景。重构 QuartzSchedulerService 的触发器同步逻辑,确保定时任务正确更新。在添加/编辑触发器时增加 Cron 表达式格式校验,避免无效表达式导致调度失败。同时修复 ScriptService 中任务启动时的线程调度问题。
2.7 KiB
2.7 KiB
本项目使用了 WPF-UI、 CommunityToolkit.Mvvm、Microsoft.Xaml.Behaviors.Wpf 来实现 MVVM 架构。在编写代码的时候请注意:
主要依赖框架
UI 框架
- WPF-UI (4.0.2) - 现代化 WPF UI 框架
- gong-wpf-dragdrop(3.2.1) - 拖拽框架
MVVM 框架
- CommunityToolkit.Mvvm (8.2.2) - 微软官方 MVVM 工具包
- 所有 ViewModel 必须继承自
ObservableObject - 使用
[ObservableProperty]特性自动生成属性 - 使用
[RelayCommand]特性自动生成命令
- 所有 ViewModel 必须继承自
- Microsoft.Xaml.Behaviors.Wpf(1.1.122) - WPF 行为扩展库
- 请尽量使用 Behaviors 库来实现交互,避免不符合 MVVM 规范的交互事件触发方式。
其他框架使用要求
- 请优先使用 Newtonsoft.Json 作为json序列化工具,但是如果这个模型已经被System.Text.Json序列化过了,那么就直接使用System.Text.Json反序列化。
- 所有简单的对话框弹出需求优先使用 ThemedMessageBox 弹出。而不是 WPF 自带的 MessageBox。
MVVM 架构规则
基础架构
ViewModel 编写规范
-
继承规则
public partial class ExampleViewModel : ViewModel { [ObservableProperty] private string _title = ""; [RelayCommand] private void DoSomething() { // 实现逻辑 } } -
属性命名
- 私有字段使用下划线前缀:
_fieldName - 公共属性使用 PascalCase:
PropertyName - 使用
[ObservableProperty]自动生成属性
- 私有字段使用下划线前缀:
-
命令实现
- 使用
[RelayCommand]特性 - 异步命令使用
[RelayCommand]+async Task
- 使用
View 编写规范
-
代码后置
public partial class ExamplePage : UserControl { public ExampleViewModel ViewModel { get; } public ExamplePage(ExampleViewModel viewModel) { ViewModel = viewModel; DataContext = this; InitializeComponent(); } } -
XAML 绑定
- 使用
{Binding}语法绑定 ViewModel 属性 - 命令绑定:
Command="{Binding ExampleCommand}" - 避免在 XAML 中编写复杂逻辑
- 使用
依赖注入规范
- 服务注册
// 在 App.xaml.cs 中注册 services.AddView<ExamplePage, ExampleViewModel>(); services.AddSingleton<IExampleService, ExampleService>();
最后,程序能够编译就认为成功,无需实际运行程序。
编译指令参考,如果出现程序占用场景,直接放弃编译验证即可
dotnet build BetterGenshinImpact.sln -c Debug
###其他要求
- 改动时候请不要删除已有的注释,你可以修改,但是不要删!