Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a WPF window be on top of all other windows of my app (not system wide)?

Tags:

c#

wpf

topmost

I want my window to be on top of all other windows in my application only. If I set the TopMost property of a window, it becomes on top of all windows of all applications and I don't want that.

like image 938
Sylvain Avatar asked Mar 30 '10 15:03

Sylvain


People also ask

How do I keep windows on top of WPF?

Basically, to keep it on top you just set the lose focus event to make it go back to top.

How do I open a WPF window in full screen?

Currently, the only way I know how to fullscreen my wpf application is: WindowStyle=None and WindowState=Maximized (and Topmost=True, though this is just needed to make sure it's above everything else).

How do I center a WPF window?

Centring Windows To open a new window and have it centred on the screen, set the WindowStartupLocation property to CenterScreen. You can do this using the XAML or in code before the window is displayed. Run the program and click the button to see the result.


1 Answers

You need to set the owner property of the window.

You can show a window via showdialog in order to block your main window, or you can show it normal and have it ontop of the owner without blocking the owner.

here is a codeexample of the codebehind part - I left out all obvious stuff:

namespace StackoverflowExample {   public partial class MainWindow : Window   {     public MainWindow()     {       InitializeComponent();     }     void NewWindowAsDialog(object sender, RoutedEventArgs e)     {       Window myOwnedDialog = new Window();       myOwnedDialog.Owner = this;       myOwnedDialog.ShowDialog();     }     void NormalNewWindow(object sender, RoutedEventArgs e)     {       Window myOwnedWindow = new Window();       myOwnedWindow.Owner = this;       myOwnedWindow.Show();     }   } } 
like image 166
Johannes Avatar answered Oct 08 '22 07:10

Johannes