#region Apache License 2.0
/*
Nuclex Foundation libraries for .NET
Copyright (C) 2002-2025 Markus Ewald / Nuclex Development Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion // Apache License 2.0
using System;
using System.Threading.Tasks;
#if NET6_0_OR_GREATER
using System.Runtime.Versioning;
#endif
using MessageBoxIcon = MsBox.Avalonia.Enums.Icon;
using MessageBoxButtons = MsBox.Avalonia.Enums.ButtonEnum;
using MessageDialogResult = MsBox.Avalonia.Enums.ButtonResult;
namespace Nuclex.Avalonia.Messages {
/// Contains helper methods for the message service
#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public static class MessageServiceHelper {
/// Asks the user a question that can be answered with yes or no
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static Task AskYesNoAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestionAsync(
MessageBoxIcon.Question, text, MessageBoxButtons.YesNo
);
}
/// Asks the user a question that can be answered with ok or cancel
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static Task AskOkCancelAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestionAsync(
MessageBoxIcon.Question, text, MessageBoxButtons.OkCancel
);
}
///
/// Asks the user a question that can be answered with yes, no or cancel
///
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static Task AskYesNoCancelAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestionAsync(
MessageBoxIcon.Question, text, MessageBoxButtons.YesNoCancel
);
}
/// Displays an informative message
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static Task InformAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowNotificationAsync(MessageBoxIcon.Info, text);
}
/// Displays a warning
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static Task WarnAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowNotificationAsync(MessageBoxIcon.Warning, text);
}
/// Reports an error
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static Task ReportErrorAsync(
this IMessageService messageService, MessageText text
) {
return messageService.ShowNotificationAsync(MessageBoxIcon.Error, text);
}
}
} // namespace Nuclex.Avalonia.Messages