Bring a window to the front in WPF
I have found a solution that brings the window to the top, but it behaves as a normal window:
if (!Window.IsVisible){ Window.Show();}if (Window.WindowState == WindowState.Minimized){ Window.WindowState = WindowState.Normal;}Window.Activate();Window.Topmost = true; // importantWindow.Topmost = false; // importantWindow.Focus(); // important
In case you need the window to be in front the first time it loads then you should use the following:
private void Window_ContentRendered(object sender, EventArgs e){ this.Topmost = false;}private void Window_Initialized(object sender, EventArgs e){ this.Topmost = true;}
Or by overriding the methods:
protected override void OnContentRendered(EventArgs e){ base.OnContentRendered(e); Topmost = false;}protected override void OnInitialized(EventArgs e){ base.OnInitialized(e); Topmost = true;}