简体   繁体   中英

Get Focused Window in WPF to front

I have a UserControl and a DialogResult Window that opens as a result of a button click in the UserControl. When both of them are open and when the user clicks the UserControl, I want to bring the UserControl to front and when he is on the UserControl and selects the DialogWindow I want to get Dialog Window to front. Please help. Please provide some sample code. Thanks.

If it is coming up behind your other windows, on your DialogWindow.xaml.cs you can set

this.Topmost = true;

EDIT: I assume your UserControl is hosted in a window itself. So now you have your 'main' window and your 'dialogWindow'.

To get your 'main' window to be topmost, you can get the parent window of your user control. In your UserControl.cs, you can have this on your PreviewLeftMouseButtonDown event

        Window parentWindow = Window.GetWindow(this);
        parentWindow.Topmost = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM