Application focus changed after closing messagebox - wpf

In our WPF application We open one window for authentication as showdialog and set owner as Mainwindow. After authentication we open another window as showdialog and set owner as Mainwindow then close the previous window using coding. When close the second window manually, the focus changed automatically to some other applications. Any help on this is highly appreciated.
Thanks

To avoid all trouble with MessageBox class, always show message box from dispatcher thread and set it's owner window properly.
MessageBox class uses Win32 api with the same name, and it should not be called from background threads.
In this case, simple Dispatcher.Invoke call will fix the issue.

Related

Prevent user interaction with modal dialog while automating UI?

I am automating a "save as" dialog through win32 API in a WPF project. The dialog is called internally from the IOleCommandTarget interface of InfoPath 2013. So I do not have access to how the save as window is initialized as far as a DoModal() method or anything similar.
The issue is I do not want the user to be able to interact with the save as window at all. Some things I have tried are ShowWindow with SW_HIDE, SetWindowPos to move the window off screen or below the main application window, and SetLayeredWindowAttributes to make the window transparent. None of these approaches has worked to hide the dialog.

How to close previous window when it redirects to another window in wpf mvvm using caliburn micro?

I am using caliburn micro in my project with mvvm architecure. I created on user control with a single button. when i click on the button it is redirecting to another user control. But the problem is when i redirect to another window, it is attaching to the previous window.
So, can any one help me to how to close the previous window when it redirects to another window.?
Thanks.
This is an old question, but the way I would go about solving this issue is use IoC/MEF to get a reference to the window manager, do a WindowManager.CreateWindow(NewViewModel) to open a new window, then TryClose() the old window.

How to show an Alert window always on top even if a new window is invoked with ShowDialog later on

In my app I have few windows which are displayed using ShowDialog, but we are trying to implement an Alerts window, if Alert window is raised we want it to be always on top even if the ShowDialog window are raised afterwards.
I have set the Alerts window's TopMost and TopLevel properties to 'true', but if a ShowDialog window comes up later, have noticed that even though Alerts window is on top, it is not clickable, while the ShowDialog window is behind, it is clickable and only after closing it the Alerts Window is accessible.
Any idea on how to achieve this?
ShowDialog creates a Modal dialog. This means that the dialog MUST be closed before interaction is allowed with the main application (this is enforced by windows).
You need to use modeless dialogs (Use Show instead of ShowDialog to achieve this), or as #rheitzman suggested, make the alerts a different application so the modal dialog rules no longer apply.

WPF Window flash notification?

I've started using the XCEED MessageBox recently, which uses custom chromes (<-I think that's their name) for the title bar, and it seems that there is no handling for the case when a dialog window (or modal dialog in Win32 terms) needs to flash in response to the user trying to click on the (disabled) parent window.
The flashing border animation is usefull to notify a user that he must respond to a dialog before continuing and to give a hint on which dialog window is that.
Is there a way to get notified when a window needs to perform the flash animation in WPF or set XAML triggers for it?

How to Open modal window/dialog in XBAP Application?

In WPF, if i want to open a modal/response window then i write code like
Window1 _windowObj1 = new Window1();
_windowObj1.Owner = mainWindowObject;
_window1Obj.ShowDialog();
How to do the same in XBAP. I tried it, but the window is opened independently from the parent page as i cant assign it as a Owner of modal window.
How to Open modal window/dialog in XBAP Application?
I'm not really experienced with XBAP apps, but I believe you should try displaying "popups" in an adorner layer. This has the same effect (you can't access the rest of the application), but doesn't actually open another window according to windows. Google for "wpf adorner dialog" and you should get some results.
Here are some links:
How do I make modal dialog for a Page in my WPF-application?
http://www.codeproject.com/KB/silverlight/slmodal.aspx
http://www.codeproject.com/KB/WPF/wpfmodaldialog.aspx
You did implement Window of WPF? If so, it will not work in XBAP. Please host your UserControl to Windows.Form, then you can open modal window/dialog in XBAP Application

Resources