I have a WPF application where i show a dialog with
nrDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
bool? dialogResult = nrDialog.ShowDialog();
The dialog is a simple Window object with properties
Title="NewReportDialog" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ResizeMode="NoResize">
The windows works as normal modal dialog and locks mainwindow as it should , but when i click on the application icon on the taskbar, Windows 7, the modal dialog goes out of focus and the only way to get the dialog back in to focus is to use ALT-Tab
Anyone has a solution?
Try to set the Owner of the dialog Window to be the main application window. This should solve the issue.
Probably something like:
nrDialog.Owner = this;
Where this is the main window instance. You can replace it with something more relevant to your case.
You can get the main application window using: Application.Current.MainWindow
Related
I am launching a modal dialog from the MainWindow in a WPF application by doing something like this.
SomeView view = new SomeView();
view.ShowDialog();
The Modal dialog contains a combo box inside to let the user select an option and then return to the main application. Problem is when ever the user hovers the mouse over the modal Dialog(SomeView) , it gets a Busy cursor. If the user moves the mouse outside the area of the ModalWindow( into the MainWindow's real estate), the cursor goes back to normal. But when ever it is inside the modal window, the cursor shows busy. However, the user is able to click and proceed with the application.
If I launch the window as modeless , by calling
SomeView view = new SomeView();
view.Show();
Then I do not see the busy cursor.
Does any one have a clue on why it is happening? or ways to find out the rootcause. I am able to fix the issue by doing the following, but I wanted to understand the rootcause. Also Setting the cursor property on the ModalWindow is not helping.
The following works.
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
window.ShowDialog();
Mouse.OverrideCursor = null;
Thanks in advance.
Sumit.
Is it possible to switch or activate other windows when modal window is open?
Window1 window = new Window1();
window.ShowDialog();
If I understood you correctly you can do something like the following:
Window1 window = new Window1();
window.Activate();
This will activate window and bring it to the foreground.
I don't think it's possible to set the control back to parent form from a modal window(That's the point of using Modal Window). You can use non modal window.
window.Show();
If you use window.Activate(); it will not show the form.
How can i keep my main window maximized in wpf app.
when i open second window and do something in that and close it, my main window get minimized.
please help me.
in fact i have three window:
A main window that application start with that.
A second window that shows a list of entities. with edit, delete and add button.
The third window that is for editing the selected entity.
when i close the third and second window, my main window get minimized.
i use the below code for opening second and third windows:
SecondWindow win = new SecondWindow();
win.Owner = this;
win.ShowDialog();
thanx.
I think Your problem is: something about how you show Main-dialog not other Forms!. Can you provide how Show Main-dialog?
also you can try use WindowState="Maximized" on your Main-dialog.
I have an application on C#/WPF that I`m developing ... I have a btn named About which should open a new window that contains details about the application or whatever I will put in it.
When I click the btn, a new window (about) opens, when I click again, while the new window (about) is opened another one is opened, how can I prevent this from happening, I also want the application to be disabled when the About window is opened and to be enabled when the About window is closed, Like most of the applications when about is clicked.
You should use the ShowDialog Method: http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx
Code Sample:
// Instantiate window
AboutWindow aboutWindow = new AboutWindow();
// Show window modally
// NOTE: Returns only when window is closed
Nullable<bool> dialogResult = aboutWindow.ShowDialog();
Just use ShowDialog() method instead of Show()
AboutWindow aboutWindow = new AboutWindow();
aboutWindow.ShowDialog();
C#
how to enable focus in the main frame, when a new window was opened and there is no way to activate actions in the main frame.
Thanks,
If you are opening the new window from within the main window, then you can make your new window modeless and set this.Focus() to set focus.
From MSDN:
... A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application
Modeless forms let you shift the focus between the form and another form without having to close the initial form. The user can continue to work elsewhere in any application while the form is displayed.