In my solution, I have a project that contains MainWindow (a.k.a., the main window of my application). In another project in the same solution, I have a chat client user control that displays a notification window when the user receives a new message.
I want my notification window to pop-up on top of MainWindow wherever MainWindow might appear. The code below works as long as the user has 1 monitor OR MainWindow is maximized if multiple monitors. However, if MainWindow is minimized, the notification appears in the top right of the working area, not MainWindow.
I have tried each of the code sets below (executed in ChatClient.xaml.cs) with no success.
private const double topOffset = 0;
private const double leftOffset = 300;
popNotification.Top = Application.Current.MainWindow.Top + topOffset;
popNotification.Left = Application.Current.MainWindow.Width - leftOffset;
OR
popNotification.Top = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top + topOffset;
popNotification.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - leftOffset;
How do I get my notification window to always display on top of MainWindow? Should I execute it inside MainWindow.xaml.cs? Thanks for any help!
EDIT
The code below also causes my application (via MainWindow) to crash. Best I can tell, this sets the window owner to the user control, not MainWindow. What do I need to do instead?
popNotification.Owner = Window.GetWindow(this);
Also tried this:
popNotification.Owner = Window.GetWindow(Application.Current.MainWindow);