Files
better-genshin-impact/BetterGenshinImpact/View/Windows/GearTask/AddTriggerDialog.xaml.cs
辉鸭蛋 f59043d708 feat(触发器): 添加触发器编辑功能
- 在触发器页面添加“编辑选中项”按钮
- 扩展添加触发器对话框以支持编辑模式
- 实现触发器数据的回显和更新逻辑
- 通过绑定动态更新对话框标题
2026-02-17 21:55:42 +08:00

100 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Windows;
using BetterGenshinImpact.Helpers.Ui;
using BetterGenshinImpact.ViewModel.Windows.GearTask;
using BetterGenshinImpact.ViewModel.Pages.Component;
using Microsoft.Extensions.DependencyInjection;
using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.View.Windows.GearTask;
public partial class AddTriggerDialog
{
public AddTriggerDialogViewModel ViewModel { get; }
public AddTriggerDialog(AddTriggerDialogViewModel viewModel)
{
ViewModel = viewModel;
DataContext = ViewModel;
InitializeComponent();
ViewModel.RequestClose += OnRequestClose;
this.SourceInitialized += OnSourceInitialized;
this.Loaded += OnLoaded;
}
private void OnSourceInitialized(object? sender, EventArgs e)
{
// 应用与主窗口相同的背景主题
WindowHelper.TryApplySystemBackdrop(this);
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
// 自动聚焦到名称输入框
TriggerNameTextBox.Focus();
TriggerNameTextBox.SelectAll();
}
private void OnRequestClose(object? sender, bool result)
{
DialogResult = result;
Close();
}
/// <summary>
/// 显示新增触发器对话框
/// </summary>
/// <returns>如果用户点击确定返回创建的触发器ViewModel否则返回null</returns>
public static AddTriggerDialogViewModel? ShowAddTriggerDialog()
{
// 使用依赖注入获取 ViewModel
var storageService = App.GetRequiredService<GearTaskStorageService>();
var logger = App.GetRequiredService<ILogger<AddTriggerDialogViewModel>>();
var viewModel = new AddTriggerDialogViewModel(storageService, logger);
var dialog = new AddTriggerDialog(viewModel)
{
Owner = Application.Current.MainWindow
};
var result = dialog.ShowDialog();
return result == true ? dialog.ViewModel : null;
}
/// <summary>
/// 显示新增触发器对话框,指定触发器类型
/// </summary>
/// <param name="predefinedType">预定义的触发器类型</param>
/// <returns>如果用户点击确定返回创建的触发器ViewModel否则返回null</returns>
public static AddTriggerDialogViewModel? ShowAddTriggerDialog(TriggerType predefinedType)
{
// 使用依赖注入获取 ViewModel
var storageService = App.GetRequiredService<GearTaskStorageService>();
var logger = App.GetRequiredService<ILogger<AddTriggerDialogViewModel>>();
var viewModel = new AddTriggerDialogViewModel(storageService, logger, predefinedType);
var dialog = new AddTriggerDialog(viewModel)
{
Owner = Application.Current.MainWindow
};
var result = dialog.ShowDialog();
return result == true ? dialog.ViewModel : null;
}
public static AddTriggerDialogViewModel? ShowEditTriggerDialog(GearTriggerViewModel existingTrigger)
{
var storageService = App.GetRequiredService<GearTaskStorageService>();
var logger = App.GetRequiredService<ILogger<AddTriggerDialogViewModel>>();
var viewModel = new AddTriggerDialogViewModel(storageService, logger, existingTrigger);
var dialog = new AddTriggerDialog(viewModel)
{
Owner = Application.Current.MainWindow
};
var result = dialog.ShowDialog();
return result == true ? dialog.ViewModel : null;
}
}