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?
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).
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.
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.
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.
You could use Window.Activate instead:
window.Activate();
This is the WPF equivelent to calling SetForegroundWindow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With