wpf - Close all open modal dialog windows -


i have wpf application has several modal window used various purposes. accomplished using showdialog function. however, in application have timer measure idle time (i.e. no mouse moves or key strokes) cause user logged off. there way (when timer fires) find , close open modal windows without tracking each explicitly?

update close messagebox.show instances. possible?

thanks, matt

is there way (when timer fires) find , close open modal windows without tracking each explicitly?

you use componentdispatcher.isthreadmodal check see if you're ui thread in modal state. if is, application.current.windows property give list of opened windows.

if have single mainwindow, close others (as they'd modal dialogs), if have multiple windows, you'd have check each one.

unfortunately, there's no direct api determine whether specific window modal - there private variable in window class use this. example, following method uses reflection determine whether window modal:

  public static bool ismodal(window window)   {        type type = typeof(window);        var field = type.getfield("_showingasdialog", bindingflags.instance | bindingflags.nonpublic);        return field.getvalue(window);   } 

this is, unfortunately, subject change (since it's using undocumented private members).


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -