Files
better-genshin-impact/BetterGenshinImpact/View/Windows/GearTask/AddTaskNodeDialog.xaml.cs

52 lines
1.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 AddTaskNodeDialogViewModel = BetterGenshinImpact.ViewModel.Windows.GearTask.AddTaskNodeDialogViewModel;
namespace BetterGenshinImpact.View.Windows.GearTask;
public partial class AddTaskNodeDialog
{
public AddTaskNodeDialogViewModel ViewModel { get; }
public AddTaskNodeDialog(string taskType)
{
ViewModel = new AddTaskNodeDialogViewModel(taskType);
DataContext = ViewModel;
InitializeComponent();
ViewModel.RequestClose += OnRequestClose;
this.SourceInitialized += OnSourceInitialized;
}
private void OnSourceInitialized(object? sender, EventArgs e)
{
// 应用与主窗口相同的背景主题
WindowHelper.TryApplySystemBackdrop(this);
}
private void OnRequestClose(object? sender, bool result)
{
DialogResult = result;
Close();
}
/// <summary>
/// 显示添加任务对话框
/// </summary>
/// <param name="taskType">任务类型</param>
/// <param name="owner">父窗口</param>
/// <returns>如果用户点击确定返回ViewModel否则返回null</returns>
public static AddTaskNodeDialogViewModel? ShowDialog(string taskType, Window? owner = null)
{
var dialog = new AddTaskNodeDialog(taskType);
if (owner != null)
{
dialog.Owner = owner;
}
var result = dialog.ShowDialog();
return result == true ? dialog.ViewModel : null;
}
}