WPF 'Toaster' Popup - How to close? - c#

I'm using the following to create 'toaster' style pop-ups:
Create popup "toaster" notifications in Windows with .NET
Unfortunately, after the message "disappears", there is still a 'task' in the taskbar. After showing multiple popups, there is a separate 'task' for each popup that was opened, all stacked on top of each other.
How can I close these after the opacity animation has completed?

I wrote my own toast implementation, perhaps you can find use of it! It's very simple, all you do is:
ToastMessage.Show("My message", "My Title");
And you're done! :) I'll keep updating it until I think it's perfect, but modify it as you wish! I'm yet to add things like animations and sound effects.
Here is the link:
GitHub WPFToastMessage

I figured this out and it's pretty easy!
I changed this (minus space at beginning):
< Storyboard>
To this:
< Storyboard Completed="Storyboard_Completed">
Then in the 'properties' pane under events, I double-clicked the new event that was auto-added and got this:
private void Storyboard_Completed(object sender, EventArgs e)
{
}
And simply added:
this.Close();

Related

C# WPF Caliburn.micro handling opening and closing windows

1153/5000
I spent the last two days searching for a solution. Unfortunately, I found nothing, or at least nothing that would explain to me how to manage opening and closing windows.
I am new to programming, maybe that's the main problem.
But, my problem is:
I am doing a small WPF program using caliburn.micro and mwwm. The problem is opening and closing windows.
I would like to do a window management class or something like that, but I don't know how to aproach.
Could you explain to me step by step how to do it? I read the caliburn.micro documentation, but it doesn't explain how to do it.
In general, the situation looks like this:
I have a main window from which you can open several others. When i'm opening a window, the main window disappears. After closing that window, the main menu appears again. I did it with:
'''App.Current.MainWindow.Show();'''
I would like to manage all windows. Opening them and closing. I came to the point that I should do it with Iwindowmanager ... but how? What? Where? I have no idea. Hence the request for a step-by-step explanation.
ps. Forgive me my English.
edit:
757/5000
There's a problem with that, I don't have much code because I don't know how to go about it. And wherever I was looking, I couldn't find a hint.
But of course I will show what I have:
To open one window from the main menu I have this:
IWindowManager manager = new WindowManager();
public MenuView()
{
InitializeComponent();
}
private void ActionButton_OnClick(object sender, RoutedEventArgs e)
{
manager.ShowDialog( new FirstViewModel(), null, null);
this.Hide();
}
To close this window I'm using
App.Current.MainWindow.Show();
this.Close();
but if I use the first part of the code in a window other than the main menu, I don't know how to go back.

Black areas on inherited ToolStrip [duplicate]

I use StatusStrip that contains ToolStripStatusLabel. OS - Windows 7, framework 2.0.
Usually all displayed normal, but sometimes ToolStripStatusLabel looks like black box:
I read that windows bug, but how I can fix it?
This is an obscure bug, triggered when you display the form with the Windows toolbar overlapping your StatusStrip. Moving the window away from the toolbar doesn't get the ToolStripItems on the status strip repainted properly. You'll find a bit of background in this forum post. There was a weak promise for a future fix for it, no idea if that ever happened. Probably not if you are running this on Win7.
You'll need to pay more attention to the position of the window, making sure that parts of it don't disappear underneath the toolbar. In general something you'd always consider, extra important as long as this bug doesn't get fixed. If you don't want to nail down the startup position (you ought to, users tend to like a window getting redisplayed where they last moved it) then simply change the form's StartPosition property to "CenterScreen".
This bug has never been fixed. It was in framework 2 and is still in framework 4.
The answer from Hans is a copy of the answer in social.msdn.microsoft.com.
But it is not helpful for me because "CenterScreen" does not solve the problem.
The cause of the problem is not the Windows Taskbar. The cause is a bug that does not draw the StatusStrip when the main Form is behind ANY other window at the first moment of drawing the StatusStrip. But this will also happen when you start the new process with Process.Start() from another process and the new process opens behind the window of another process.
I found a much better solution than the one proposed by Microsoft.
First I tried with
statusStrip.Invalidate();
but it does not work. So we need a stronger way to force Windows to redraw the StatusStrip. Important: The redrawing must happen when the Form with the StatusStrip is ALREADY in foreground! This is so easy that I don't understand why Microsoft does not suggest this method.
Timer mi_StatusTimer = new Timer();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
mi_StatusTimer.Interval = 500;
mi_StatusTimer.Tick += new EventHandler(OnTimerBugFix);
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
mi_StatusTimer.Start();
}
void OnTimerBugFix(object sender, EventArgs e)
{
mi_StatusTimer.Stop();
statusStrip.Hide();
Application.DoEvents();
statusStrip.Show();
}

VSTO splash screen or progress bar

I have a project that I'm doing with
Microsoft VSTO (office 2013 excel)
I have certain things that make calls that take maybe 10 seconds to come back.
Ideally I would like to display an progress bar or some status... After a lot of searching I found an article that is titled:
How do I create a splash screen window for the VSTO applications?
http://www.datazx.cn/Fv7p5a/xw/oa2v/2q7xs6/mcccjfti-988m-f8r8-8d44-bstb4rfsi4xm23rsdfd.html
So I started creating this code in a form, but then I realize that I need to call it up within my methods and really attach events etc...
The article says to
"display a modal form on a background thread" What is the best way to do this?
I find it easier to use modal less form on main thread and so far haven't seen any problem with modal less approach. Something like code below
var splashWindow = new SplashWindow();
splashWindow.Show();
splashWindow.SetMessage("Starting please wait...");
DoSomeWork(splashWindow);
splashWindow.Close();
Following you will see a way I programmed a Splash Screen for Excel-VSTO in C#. My Excel file is enabled for macros (.xlsm). These are the steps:
Create your splash screen. Let's assume the name of the form is SplashScreen.
Go to the code of the object ThisWorkbook.cs
Check the code looks like:
public partial class ThisWorkbook
{
SplashScreen SC = new SplashScreen();
private async void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
SC.Show();
await Task.Delay(3500);
SC.Close();
more code...
}
}
It is important that you notice that I added the word async to the subroutine.
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
I hope this is very useful.

Silverlight 4 Transition Animations Between Adding/Removing Grid Child Elements

I'm using the Silverlight Wizard control provided by this blog:
http://weblogs.asp.net/bryansampica/archive/2010/07/21/silverlight-4-0-wizard-custom-control.aspx
And I would like to add a transition between ActivePage changes...the way they are handled in the codebehind are like so:
public void manager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
ContentHost.Children.Clear();
ContentHost.Children.Add(manager.ActiveStep);
HeaderText = manager.ActiveStep.StepHeaderText;
}
Is there any way to add an animation between the Clear & Add?
My apologies if this is a silly question!
Thanks!
One way to get the desired effect would be to launch a Storyboard which handles the visual transition, then listen on the Completed event to update the ContentHost.Children.
In a storyboard animate ContentHost.Opacity to 0
When the Storyboard.Completed event fires, execute the code in your manager_PropertyChanged() code block
Launch a second Storyboard to animate ContentHost.Opacity back to 1

Creating a Popup Balloon like Windows Messenger or AVG

How can I create a Popup balloon like you would see from Windows Messenger or AVG or Norton or whomever?
I want it to show the information, and then slide away after a few seconds.
Edit: It needs to be blocking like Form.ShowDialog() because the program exits after displaying the notification
You can use the notifyIcon control that's part of .NET 2.0 System.Windows.Forms. That allows you to place an icon for your application in the System Tray. Then, you can call the ShowBalloonTip(int timeOut) method on that. Be sure however to first set the text, and icon properties on the notifyIcon for it to work. Small code sample:
private void button1_Click(object sender, EventArgs e)
{
this.notifyIcon1.BalloonTipText = "Whatever";
this.notifyIcon1.BalloonTipTitle = "Title";
this.notifyIcon1.Icon = new Icon("icon.ico");
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(3);
}
EDIT: Ok, so notifyIcon won't work for you. My second suggestion would then be to create your own control for this. Actually, I would use a form. A simple form, with no borders, and no control box and just have a timer running so you can set the Opacity for fade in/out. Then, you can easily get the bottom right of the screen using the Rectangle Screen.PrimaryScreen.WorkingArea. Then just show your form at that position.
Don't create a modal (blocking) balloon. Please. A big part of the design of these UIs is that they are not dialogs: they're transient, potentially non-interactive elements, intended to provide incidental information to a user without necessarily interrupting their workflow. A balloon that steals focus and blocks user input would be irritating at best - if you need a dialog, then use a dialog.
The .NET 1.1 Visual Basic Power Pack had a toaster control.

Categories