Files
ShrlAlgoToolkit/WPFluent/Controls/Toast/Toast.cs
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

48 lines
2.6 KiB
C#

using System.Linq;
using System.Windows;
namespace WPFluent.Controls;
public static class Toast
{
public static void Information(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(owner, message, new ToastConfig(ToastIcon.Information, offsetMargin, time));
public static void Information(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(null!, message, new ToastConfig(ToastIcon.Information, offsetMargin, time));
public static void Success(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(owner, message, new ToastConfig(ToastIcon.Success, offsetMargin, time));
public static void Success(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(null!, message, new ToastConfig(ToastIcon.Success, offsetMargin, time));
public static void Error(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(owner, message, new ToastConfig(ToastIcon.Error, offsetMargin, time));
public static void Error(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(null!, message, new ToastConfig(ToastIcon.Error, offsetMargin, time));
public static void Warning(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(owner, message, new ToastConfig(ToastIcon.Warning, offsetMargin, time));
public static void Warning(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(null!, message, new ToastConfig(ToastIcon.Warning, offsetMargin, time));
public static void Question(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(owner, message, new ToastConfig(ToastIcon.Question, offsetMargin, time));
public static void Question(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
=> Show(null!, message, new ToastConfig(ToastIcon.Question, offsetMargin, time));
public static void Show(FrameworkElement owner, string message, ToastConfig? options = null)
{
ToastControl toast = new(
owner ?? Application.Current.Windows.OfType<Window>()
.Where(win => win.IsActive)
.FirstOrDefault()!,
message, options);
toast.ShowCore();
}
}