using WPFluent.Controls; namespace WPFluent.Extensions; public static class MessageExtensions { private static readonly IContentDialogService ContentDialogService = new ContentDialogService(); private static readonly SnackbarService SnackbarService = new(); 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 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 async void ShowMessage(string content = "内容...", string title = "消息") { Controls.MessageWindow 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 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" //}; } }