Hi guys,
I was developing a WPF application that should open a window after clicking tray icon and bumped with a problem when focusing, The same method would be called whether the window was open or not, so the easiest way I've found to do that is the following:
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(int hWnd);
private void BringToFront()
{
if (!IsVisible)
Visibility = Visibility.Visible;
SetForegroundWindow((new System.Windows.Interop.WindowInteropHelper(this)).Handle);
}Hope this helps!
Source:
http://www.dotnetspider.com/resources/5772-Bring-e-window-Front-set-It-Active-window.aspx