Enterwell / Wpf.Notifications

WPF notifications UI controls (as seen in VS Code)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make it disapear after n seconds?

filipjelic opened this issue · comments

commented

Is it possible to make it disappear after n seconds, implement like a small timer instead of just clicking buttons?
Let's say I get a notification and if I don't click it for 5 seconds it automatically disappears...

Currently no such extension method is available if you're using LINQ builder, but you can try doing something like this:

var builder = this.Manager
    .CreateMessage()
    .Accent("#E0A030")
    .Background("#333")
    .HasBadge("Warn")
    .HasMessage("Failed to retrieve data.")
    .WithButton("Try again", button => { });

Task.Delay(5000).ContinueWith(ctx => this.Manager.Dismiss(builder.Message));

builder.Queue();
commented

Okay, that will do, thanks for help...

@AleksandarDev i tested your code but i get error:
The calling thread cannot access this object because a different thread owns it.'

this worked for me:

 builder.Queue();
                await Task.Delay(5000);
                this.Manager.Dismiss(builder.Message);

@ghost1372 Thanks for reporting the problem.
That's probably because this.Manager.Dismiss needs to be called on UI thread (with Dispatcher).

Task.Delay(5000).ContinueWith(ctx => 
    this.Manager.Dismiss(builder.Message), 
    TaskScheduler.FromCurrentSynchronizationContext());

This should work if you don't want to make the calling method async and do the await call.

I'm planning to implement delayed dismiss with builder like it is specified here #5 . Is this what you had in mind?

@ghost1372 @arcticwhite

commented

@AleksandarDev Yeah exactly that!
It would be great with some kind of animation, like fade-out to disappear. But for now it's ok.

@arcticwhite I'll create animation tak, but it's not on my priority list right now. Everyone is welcome to make PR for that...