English 中文(简体)
新温得后方案停止
原标题:Program doesn t stop after new Window
  • 时间:2011-04-26 14:41:06
  •  标签:
  • c#
  • .net
  • wpf

C#, WPF, NET 4.0:

如果我在窗口衍生的班子上做新事,而在这个窗户上不叫Sudialog,我的节目就关闭了。

例:

        Window d = new Window();
        //d.ShowDialog();

为什么如此?

我不想展示窗户,我只想把这个目标用于某种目的。 因此,我必须做些什么才能允许我的方案在随后关闭?

最佳回答

您很可能将申请编成“, 仅限<>>。 当其所有窗户都关闭时,通过建立一个从未关闭的新窗口,你的申请永远不会被关闭。

This setting is governed by the Application.ShutdownMode property, which specifies the condition that causes the Shutdown method to be called. Essentially, you have three options.

  1. 首先,正如你所见,除非和直到它创造的所有窗口都已关闭,否则你的申请不会结束。 无论是用户还是通过打电话<代码>将其关闭,都无关紧要。 近方法。

    这一选择通过制定<条码>申请加以规定。 ShutdownMode property to OnLastWindowClose

  2. 第二种方法利用了这样一个事实,即几乎所有申请都有“主要”窗口(这是你在申请启动时首先展示的窗口),而且在关闭这一主要窗口时,操作时间自动关闭了你的全部申请(和所有的儿童窗口)。 同样,窗户是否被用户关闭或通过密码关闭,也无关紧要。

    这一选择通过制定<条码>申请加以规定。 ShutdownMode property to OnMainWindowClose

  3. 第三项选择基本上表明,你将重新进行手工管理。 在你打电话Shutdown,。 穿过代码。

    This option is specified by setting the Application.ShutdownMode property to OnExplicitShutdown.

我建议,在这种情况下,你将“second>”办法设定为“second,并在用户关闭主要窗口时自动关闭你。 这将防止任何可能仍然显示的线性儿童窗口阻止你关闭。 这消除了在Stecya swer上写成的代码的必要性,使管理时间自动为你处理所有这些问题。

问题回答

you can use this code to close all windows

  private void CloseAllWindows()
  {
     foreach(var window in Application.Current.Windows)
        window.Close();
  }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签