简体   繁体   English

将WPF中的焦点窗口移到最前面

[英]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. 我有一个UserControl和一个DialogResult窗口,由于在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. 当它们都打开并且用户单击UserControl时,我想将UserControl放在前面,当他在UserControl上并选择DialogWindow时,我想将Dialog Window放在前面。 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 如果它出现在其他窗口后面,则可以在DialogWindow.xaml.cs上进行设置

this.Topmost = true;

EDIT: I assume your UserControl is hosted in a window itself. 编辑:我假设您的UserControl托管在一个窗口本身中。 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 在UserControl.cs中,可以在PreviewLeftMouseButtonDown事件中使用它

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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