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 al
I ran into a very similar situation as you. Most of the searches I came across stated all I needed to do was set the Owner of the windows I wish to be Topmost to the main window or whatever window that called Show.
Anyways, I'll go ahead and post a solution that worked well for me.
I created event handlers for Window.Activated and Window.Deactived in the window that was supposed to be Topmost with respect to my application.
private void Window_Activated(object sender, EventArgs e)
{
Topmost = true;
}
private void Window_Deactived(object sender, EventArgs e)
{
if(Owner == null || Owner.IsActive)
return;
bool hasActiveWindow = false;
foreach(Window ownedWindow in Owner.OwnedWindows)
{
if(ownedWindow.IsActive)
hasActiveWindow = true;
}
if(!hasActiveWindow)
Topmost = false;
}
It works great for me. Hopefully this is useful to someone else out there. :o)