98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using System.Threading.Tasks;
|
|
|
|
using Wpf.Ui;
|
|
using Wpf.Ui.Controls;
|
|
using Wpf.Ui.Extend.Controls;
|
|
using Wpf.Ui.Extensions;
|
|
|
|
namespace Sai.RvKits;
|
|
|
|
public static class MessageExtensions
|
|
{
|
|
private static readonly SnackbarService SnackbarService = new();
|
|
private static readonly IContentDialogService ContentDialogService = new ContentDialogService();
|
|
|
|
public static void ShowDanger(this SnackbarPresenter SnackbarPresenter, string title, string message)
|
|
{
|
|
SnackbarService.SetSnackbarPresenter(SnackbarPresenter);
|
|
SnackbarService.Show(
|
|
title,
|
|
message,
|
|
ControlAppearance.Danger,
|
|
new SymbolIcon(SymbolRegular.Alert12),
|
|
SnackbarService.DefaultTimeOut
|
|
);
|
|
}
|
|
|
|
public static void ShowInfo(this SnackbarPresenter SnackbarPresenter, string title, string message)
|
|
{
|
|
SnackbarService.SetSnackbarPresenter(SnackbarPresenter);
|
|
SnackbarService.Show(
|
|
title,
|
|
message,
|
|
ControlAppearance.Info,
|
|
new SymbolIcon(SymbolRegular.Info12),
|
|
SnackbarService.DefaultTimeOut
|
|
);
|
|
}
|
|
|
|
public static void ShowCaution(this SnackbarPresenter SnackbarPresenter, string title, string message)
|
|
{
|
|
SnackbarService.SetSnackbarPresenter(SnackbarPresenter);
|
|
SnackbarService.Show(
|
|
title,
|
|
message,
|
|
ControlAppearance.Caution,
|
|
new SymbolIcon(SymbolRegular.Question16),
|
|
SnackbarService.DefaultTimeOut
|
|
);
|
|
}
|
|
|
|
public static async void ShowMessage(string content = "内容...", string title = "消息")
|
|
{
|
|
Wpf.Ui.Controls.MessageBox uiMessageBox = new()
|
|
{
|
|
Title = title,
|
|
Content = content,
|
|
MinWidth=200,
|
|
//PrimaryButtonIcon = SymbolRegular.Button16,
|
|
//PrimaryButtonAppearance = ControlAppearance.Primary,
|
|
//PrimaryButtonText = "确定",
|
|
//SecondaryButtonIcon = SymbolRegular.Button20,
|
|
//SecondaryButtonAppearance = ControlAppearance.Secondary,
|
|
//SecondaryButtonText = "取消",
|
|
CloseButtonAppearance = ControlAppearance.Primary,
|
|
//CloseButtonIcon = SymbolRegular.CalendarCancel16,
|
|
CloseButtonText = "确定",
|
|
WindowStartupLocation = System.Windows.WindowStartupLocation.Manual,
|
|
};
|
|
await uiMessageBox.ShowDialogAsync();
|
|
}
|
|
|
|
public static async Task<ContentDialogResult> ShowTaskDialog(
|
|
string title,
|
|
object content,
|
|
string primaryButtonText = "确定",
|
|
string secondaryButtonText = "取消",
|
|
string closeButtonText = "关闭"
|
|
)
|
|
{
|
|
return await ContentDialogService.ShowSimpleDialogAsync(
|
|
new SimpleContentDialogCreateOptions()
|
|
{
|
|
Title = title,
|
|
Content = content,
|
|
PrimaryButtonText = primaryButtonText,
|
|
SecondaryButtonText = secondaryButtonText,
|
|
CloseButtonText = closeButtonText,
|
|
}
|
|
);
|
|
//result switch
|
|
//{
|
|
// ContentDialogResult.Primary => "User saved their work",
|
|
// ContentDialogResult.Secondary => "User did not save their work",
|
|
// _ => "User cancelled the dialog"
|
|
//};
|
|
}
|
|
}
|