Question:
It is necessary to create a window that opens, displays for a couple of seconds and closes itself.
In fact, this window will act as a notification.
An event occurred – a notification popped up, displayed for a couple of seconds and disappeared.
The text in the notification is different every time.
I will pass as a constructor argument, or through the DataContext.
AlarmWindow alarm = new AlarmWindow(alarmMessage);
alarm.Show();
//либо
AlarmWindow alarm = new AlarmWindow()
{
DataContext = alarmMessage
};
alarm.Show();
Answer:
Should work like this:
void TickHandler(...)
{
Application.Current.Dispatcher.InvokeAsync(async () =>
{
AlarmWindow alarm = new AlarmWindow(alarmMessage);
alarm.Show();
await Task.Delay(2000);
alarm.Close();
});
}