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 all applications and I don't want that.
views:
674answers:
5There are several threads, there's even a "topmost" tag. Search on that, or go directly to this post which looks good:
Instead you can use a Popup that will be TopMost always, decorate it similar to a Window and to attach it completely with your Application handle the LocationChanged event of your main Window and set IsOpen property of Popup to false.
Edit:
I hope you want something like this:
Window1 window;
private void Button_Click(object sender, RoutedEventArgs e)
{
window = new Window1();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = True;
this.LocationChanged+=OnLocationchanged;
window.Show();
}
private void OnLocationchanged(object sender, EventArgs e)
{
if(window!=null)
window.Close();
}
Hope it helps!!!
You can add this to your windows tags
WindowStartupLocation="CenterScreen"
Then you can also display it if you want your users to acknowledge it in order to proceed
YourWindow.ShowDialog();
First try it without TopMost parameters and see the results.
I'm the OP. After some research and testing, the answer is:
No, there is no way to do exactly that.
Here's a way to do it: make your "topmost" window subscribe to your other windows GotFocus and LostFocus events and use the following as the event handlers:
class TopMostWindow
{
void OtherWindow_LostFocus(object sender, EventArgs e)
{
this.Topmost = false;
}
void OtherWindow_GotFocus(object sender, EventArgs e)
{
this.Topmost = true;
}
}