Application.OpenForms 的 WPF 版本

发布于 2024-09-02 00:27:48 字数 643 浏览 4 评论 0原文

我有一个应用程序,我必须在其中打开另一个打开的 WPF 窗口。在 WinForms 中,我能够使用:

MainWindow main = (MainWindow)Application.OpenForms["MainWindow"];

能够访问表单。现在在 WPF 中它不存在。我已经在该网站上看到了其他相关的帖子,但是它使用未包含在调用中的 Application.Window 。我只有:

  • Current
  • Equals
  • GetContentStream
  • GetCookie
  • GetRemoteStream
  • GetResourceStream
  • LoadComponet
  • RefrenceEquals
  • ResourceAssembly
  • SetCookie

所以我的问题是,OpenForms 是否有不同的版本,或者是否有不同的方法来解决它。

I have an application in which I will have to get at another WPF window which is open. In WinForms, I was able to use:

MainWindow main = (MainWindow)Application.OpenForms["MainWindow"];

To be able to access the the form. Now in WPF it does not exist. I have seen the other post on this site which is relevant, however it uses Application.Window which is not contained in the call. I just have :

  • Current
  • Equals
  • GetContentStream
  • GetCookie
  • GetRemoteStream
  • GetResourceStream
  • LoadComponet
  • RefrenceEquals
  • ResourceAssembly
  • SetCookie

So my question is this, is there a different version for OpenForms, or is there just a different way to go about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若言繁花未落 2024-09-09 00:27:48

尝试查看:Application.Current。更具体地说,Application.Current.Windows

Try looking at: Application.Current. More specifically, Application.Current.Windows.

染年凉城似染瑾 2024-09-09 00:27:48

我可能会迟到,但以防万一有人需要这个。如果您这边缺少 Application.OpenForms,那是因为您必须使用 System.Windows.Forms.Application.OpenForms

例如:

FormCollection fc = System.Windows.Forms.Application.OpenForms;

fc 对象包含以下属性: Count 和 InnerList(非常有用)

希望它有帮助,即使是 2021 年,我认为有人会需要此信息(当我搜索它时,我在任何地方都没有看到它)

I might be late here but just in case someone needs this. If Application.OpenForms is missing on your side, that's because you have to use System.Windows.Forms.Application.OpenForms

For example:

FormCollection fc = System.Windows.Forms.Application.OpenForms;

The fc object contains properties as: Count and InnerList(very useful)

Hope it helps, even if it is 2021, I thought that someone would need this information (I haven't seen it anywhere when I searched for it)

雨轻弹 2024-09-09 00:27:48
Window2 wndw = new Window2();
wndw.Owner = this;

foreach (Window w in Application.Current.Windows)
{
    if (w.Name == wndw.Name)
    {
        if (w.IsActive)
        {
            w.Focus();
            return;
        }
        else
        {
            w.Show();
            return;
        }
    }
}
Window2 wndw = new Window2();
wndw.Owner = this;

foreach (Window w in Application.Current.Windows)
{
    if (w.Name == wndw.Name)
    {
        if (w.IsActive)
        {
            w.Focus();
            return;
        }
        else
        {
            w.Show();
            return;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文