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.
Related
I'm work on WPF project, let say I have two windows window1,window2, window1 call window2: in window1 code behind :
Window2 _window2 = new Window2();
_window2.ShowDialog();
What I want to know how I close first window (window1) after the secound window (window2) is opened ?
If "Window1" is not your main window you can just type this
Window2 _window2 = new Window2();
_window2.Show();
this.Close();
If your form is the main form than refer
(Windows Forms: Change application mainwindow at runtime)
Before you can close the main window (if it is), then you need to tell the app first which is the main window. Depending upon your shut down mode, if you close the main window, you shut down the app. You can set this using Application.Current.MainWindow property. See Here.
If you wish to close the first window after opening the second, you will need to hook up an event, or better still use a decoupled messaging system to inform the first window the second has opened.
Form1:
Window2 _window2 = new Window2();
this.Hide(); //Hides Form 1
_window2.ShowDialog();
Also see:
Close a Window from Another In Wpf
if you wanna have window1 closed.
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
I have 2 Windows in my sample App (learning .Net 4 WPF)
In the first window, I have a timer and when 5 seconds passed, i want to close the current Window and open a new Window.
The problem I'm running into is closing the first window
Here's some sample code
MainWindow m = new MainWindow();
m.ShowDialog();
this.Hide();
this.Hide never actually hides the current window. I end up with 2 windows on my screen instead of 1.
In the remarks of ShowDialog it says When this method is called, the code following it is not executed until after the dialog box is closed.
So, you can just swap the order of ShowDialog and Hide. and you have to use 'Show' or 'Close' after 'ShowDialog' to either display back first form or close it.
Also, note that closing a form (what you said want to do) is different to hiding a form (what you're currently doing).
MainWindow m = new MainWindow();
this.Hide();
m.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.
language c#, winform
how do i create a modal window or such a thing that when it still showing
i would still be able to click or interact with the main window..
thanks.
put some code please or links..
Make the dialog non-modal (use Show instead of ShowDialog), and make it top-most (TopMost = true)
Just use the overload of Form.Show() that takes a form as a parameter, like this:
Form f = new Form();
f.Show(this);
This will keep the form always on top of the form that calls it, but still let you click and access the calling form.
Some confusion here I think;
Modal is when the window blocks the underlying window, and must be closed to enable the underlying window to regain control. Form.ShowDialog(owner) is used to accomplish this.
Non-Modal is a window that is opened "in parallell" to the underlying window. Both windows can be accessed and respond to mouse and key events. Form.Show(owner) to accomplish this.
Modality by definition means that you are not able to click anywhere else. You can create another form and show it with Show() method.
Show() Method allows you to click anywhere while ShowDialog() won't