Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do bring a WPF Window to front?

Tags:

wpf

I have created a single-instance application and want to activate an already opened window if the user starts the app multiple times. This works fine however I have the problem, that if the already opened window is beyond another applications window, I must bring it to front.

I have tried window.Focus() and window.Show() but both of them seem not to work. As a workaround I use …

bool oldTopMost = window.Topmost;
window.Topmost = true;
window.Topmost = oldTopMost;
window.Focus();

… this does the job but looks to me very ugly. Has anyone a better solution for this?

like image 352
HCL Avatar asked Aug 03 '10 18:08

HCL


People also ask

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 display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

How do I change the startup window in WPF?

If you look at App. xaml class of your WPF application, you will see the following XAML code. Here the StartupUri sets the startup Window of an application. If you want to change the Startup window to some other window, just change this value.

What is WPF frontend?

WPF is used to build Windows client applications that run on Windows operating system. WPF uses XAML as its frontend language and C# as its backend languages. WPF was introduced as a part of . NET Framework 3.0 as the Windows library to build Windows client apps and the next generation of Windows Forms.


1 Answers

You could use Window.Activate instead:

window.Activate();

This is the WPF equivelent to calling SetForegroundWindow.

like image 102
Reed Copsey Avatar answered Sep 27 '22 23:09

Reed Copsey