using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Controls.Notifications;
using Avalonia.Metadata;
namespace Ursa.Controls;
///
/// A toast that can be shown in a window or by the host operating system.
///
///
/// This class represents a toast that can be displayed either in a window using
/// or by the host operating system (to be implemented).
///
public class Toast : IToast, INotifyPropertyChanged
{
private string? _content;
///
/// Initializes a new instance of the class.
///
/// The content to be displayed in the toast.
/// The of the toast.
/// The expiry time at which the toast will close.
/// Use for toasts that will remain open.
/// A value indicating whether the toast should show a close button.
/// An Action to call when the toast is clicked.
/// An Action to call when the toast is closed.
public Toast(
string? content,
NotificationType type = NotificationType.Information,
TimeSpan? expiration = null,
bool showClose = true,
Action? onClick = null,
Action? onClose = null)
{
Content = content;
Type = type;
Expiration = expiration ?? TimeSpan.FromSeconds(3);
ShowClose = showClose;
OnClick = onClick;
OnClose = onClose;
}
///
/// Initializes a new instance of the class.
///
public Toast() : this(null)
{
}
///
[Content]
public string? Content
{
get => _content;
set
{
if (_content != value)
{
_content = value;
OnPropertyChanged();
}
}
}
///
public NotificationType Type { get; set; }
///
public bool ShowIcon { get; set; }
///
public bool ShowClose { get; set; }
///
public TimeSpan Expiration { get; set; }
///
public Action? OnClick { get; set; }
///
public Action? OnClose { get; set; }
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}