74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
// Copyright (c) 2024- schick Informatik
|
|
// Description:
|
|
//
|
|
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows;
|
|
|
|
using ToastNotifications;
|
|
using ToastNotifications.Core;
|
|
using ToastNotifications.Lifetime;
|
|
using ToastNotifications.Lifetime.Clear;
|
|
using ToastNotifications.Messages;
|
|
using ToastNotifications.Position;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
internal class ToastViewModel : INotifyPropertyChanged
|
|
{
|
|
private readonly Notifier _notifier;
|
|
|
|
public ToastViewModel()
|
|
{
|
|
_notifier = new Notifier(cfg =>
|
|
{
|
|
cfg.PositionProvider = new WindowPositionProvider(
|
|
parentWindow: Application.Current.MainWindow,
|
|
corner: Corner.BottomRight,
|
|
offsetX: 25,
|
|
offsetY: 100);
|
|
|
|
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
|
|
notificationLifetime: TimeSpan.FromSeconds(30),
|
|
maximumNotificationCount: MaximumNotificationCount.FromCount(6));
|
|
|
|
cfg.Dispatcher = Application.Current.Dispatcher;
|
|
|
|
cfg.DisplayOptions.TopMost = false;
|
|
cfg.DisplayOptions.Width = 250;
|
|
});
|
|
|
|
_notifier.ClearMessages(new ClearAll());
|
|
}
|
|
|
|
public void OnUnloaded()
|
|
{
|
|
_notifier.Dispose();
|
|
}
|
|
|
|
public void ShowAppNotification(string message, MessageOptions options)
|
|
{
|
|
_notifier?.ShowAppNotification(message, options);
|
|
}
|
|
|
|
public void ShowAppNotification(string message)
|
|
{
|
|
_notifier?.ShowAppNotification(message);
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged(string? propertyName = null)
|
|
{
|
|
var handler = PropertyChanged;
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
public void ClearAll()
|
|
{
|
|
_notifier.ClearMessages(new ClearAll());
|
|
}
|
|
}
|
|
}
|