WPF ShowDialog和ElementHost [英] WPF ShowDialog and ElementHost

查看:208
本文介绍了WPF ShowDialog和ElementHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从WPF用户控件(即ElementHost的子级)显示模态窗口,并将模态窗口的所有者/父级设置为包含的Form控件?

is it possible to display a Modal Window from a WPF User Control, that is a child of an ElementHost, and set the owner/parent of the Modal Window to the containing Form control?

我想您不能执行此操作,因为Owner属性采用Window的实例,在该实例中,我想将其设置为Element Host控件的父级,Element Host控件是旧的Windows Forms Form控件.只是想知道是否有解决方法或替代方法.

I'm guessing you can't do this, as the Owner property takes an instance of Window, where as I want to set it to the parent of the Element Host control, which is an old Windows Forms Form control. Just wondering if there is a work around or alternative approach.

问题是当显示模态窗口"并且用户切换到另一个应用程序,然后再次返回时,模态窗口"被隐藏并且用户无法与主窗口进行交互.这是由于Windows认为模态窗口"仍显示,而没有显示,因为没有设置所有者/父母"关系.

The problem is when the Modal Window is displayed and the user switches to another application, then back again, the Modal Window is hidden and the user is unable to interact with the main Window. This is due to Windows thinking the Modal Window is still displayed, when it isn't, as there is no Owner/Parent relationship set.

干杯, 詹姆斯.

推荐答案

我正在使用WindowInteropHelper来解决该问题,例如:

I'm using WindowInteropHelper to solve that problem like this:

var wpfDialog = new MyWpfDialog();
var interopHelper = new WindowInteropHelper(wpfDialog)  
        {
            Owner = winFormsDialog.Handle
        };

wpfDialog.ShowDialog();

这篇关于WPF ShowDialog和ElementHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆