WPF ShowDialog 和 ElementHost
是否可以从作为 ElementHost 子级的 WPF 用户控件显示模态窗口,并将模态窗口的所有者/父级设置为包含的 Form 控件?
我猜您不能执行此操作,因为 Owner 属性采用 Window 的实例,而我想将其设置为 Element Host 控件的父级,该控件是一个旧的 Windows Forms Form 控件。只是想知道是否有解决方法或替代方法。
问题是,当显示模态窗口并且用户切换到另一个应用程序,然后再次返回时,模态窗口将被隐藏,并且用户无法与主窗口交互。这是因为 Windows 认为模态窗口仍然显示,但实际上并没有显示,因为没有设置所有者/父级关系。
干杯, 詹姆斯.
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?
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.
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.
Cheers,
James.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 WindowInteropHelper 来解决这个问题,如下所示:
I'm using WindowInteropHelper to solve that problem like this:
我知道这篇文章很旧,但我遇到了一种从 wpf UserControl 的上下文中查找托管 ElementHost 的 winform 窗口的方法,在该上下文中您可能无法访问 winform 窗口。我发现这很有用,这样我就不必传递主机窗口了。
I know this post is old, but I came across a way to find the winform window that is hosting the ElementHost from the context of a wpf UserControl where you may not have access to the winform window. I found this to be useful so that I don't have to pass the host window around.
好的,刚刚使用 WindowInteropHelper 找到了解决方案。
http://social. msdn.microsoft.com/Forums/en-US/wpf/thread/44c903fb-9514-401c-ba85-58acd5293c1b
Ok just found the solution using WindowInteropHelper.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/44c903fb-9514-401c-ba85-58acd5293c1b