using Avalonia.Controls;
namespace DispenserCommon.Utils;
public class WindowUtil
{
private static Window? _mainWindow;
public static void SetMainWindow(Window window)
{
_mainWindow = window;
}
///
/// 显示弹窗
///
/// 弹窗
/// 弹窗类型
public static void ShowDialog
(TD dialog) where TD : Window
{
if (_mainWindow == null) return;
dialog.ShowDialog(_mainWindow);
}
///
/// 显示弹窗
///
/// 弹窗
/// 弹窗回调
/// 弹窗类型
public static void ShowDialog | (TD dialog, Action | action) where TD : Window
{
if (_mainWindow == null) return;
dialog.ShowDialog(_mainWindow);
action(dialog);
}
///
/// 显示弹窗
///
/// 弹窗实体
/// 弹窗类型
/// 弹窗回调信息
///
public static async Task | ShowDialog(TD dialog) where TD : Window
{
if (_mainWindow == null) return default;
return await dialog.ShowDialog |
(_mainWindow);
}
///
/// 无返回值的弹窗
///
///
public static void ShowDialog() where TD : Window
{
if (_mainWindow == null) return;
var dialog = Activator.CreateInstance | ();
dialog.ShowDialog(_mainWindow);
}
} |