WPF: open a window in maximized state from the start - c#

I want to open a window in WPF that is already maximized as soon as it is visible.
I tried the obvious:
<Window Title="My window" WindowState="Maximized" ...>
...
</Window>
however, if I do this the window doesn't open maximized. It opens at its default size and then, half a second later, gets maximized. Is there a way to bypass this and open the window maximized from the start?
EDIT: not a duplicate of the linked question, I'm doing it the same way as the accepted answer there. My problem isn't that it doesn't work, the problem is that it doesn't work "fast enough": with that solution the window opens not maximized and then gets maximized a split second later. I want to know if there's a way to open it ALREADY maximized.

How you open the window ?
Try this.
win1 = new Window1();
win1.Show();
win1.WindowState = WindowState.Maximized;

Related

Show icon in taskbar for hidden windows

When I set the main window's visibility to hidden, No icon is shown in taskbar, so I have no control over the window to show it again. I want for the application's icon to be visible even when I hide the window, and to show the window when I click it's button in the taskbar. (something like minimize behavior)
How can I achieve that using WPF and .Net 4.0 in C#?
Edit: I mean the icon in taskbar (usually in the left and middle of the horizontal taskbar) not the notifyicon in system tray.
So, based on "comments" section, what you are looking to do is minimize or hide a window but still show some windows or dialogues that the window opens. First if you want to keep your window in the task bar, you should minimize with:
this.WindowState = WindowState.Minimized
That can be called from anywhere within the form. As you mentioned, though, this will close hide any dialogues that have this window set as the parent. The key, then is to not use this window as the parent. Lets say your dialogues inherit from form. You want to use:
newWindow.Show();
I am guessing that you are calling "ShowDialog", which ties the window state to the parent window state. Try this out and hopefully it will help!
Edit
One more note: the same is actually true of MessageBoxes, but the way to control the parent form is with the first parameter of the MessageBox.Show() call. If you pass in a form as the first parameter, that will be the parent, otherwise the parent will not be set.

Set Window almost Topmost

I code an editor, that should have a fullscreen-mode (editor covers 100% of the screen, taskbar is not visible). "Set the Window Topmost" you would say, but hereĀ“s the problem: my editor runs external programs, that have to be visible.
My editor should hide the taskbar, but not be topmost for other applications. Is this possible? And how?
You don't need a TopMost window to cover the taskbar. Creating a borderless maximized window is enough:
public MainWindow() {
InitializeComponent();
this.WindowState = System.Windows.WindowState.Maximized;
this.ResizeMode = System.Windows.ResizeMode.NoResize;
}
You still need a way for the user to activate a window of another application. It isn't clear what you had in mind, but Alt+Tab works.

window state maximize not working

I am opening a form in a mdi parent. I show the form in the parent and the window state of the new form in the designer is maximized. For some reason, the form appears in the top left corner of the mdi parent, and the control box is way over to the right as if it was maximized, but the size of the window is not filling up the screen. So the behavior is as if it were maximized, but it is not filling the screen. What should I do?
I'm using C#.Net Winform.
Set your child form's window state to maximized.
This will maximize your form.
childForm.WindowState = FormWindowState.Maximized;
You can do this on load of your MdiParent form, or whenever you open show this child form.
Make sure your MdiChilds MaximumSize Property is not set. If it is it will look like this, which looks like what you have described in your question.
Coming in late, but I too am having this problem and so far nobody's answered why it's happening. I found this discussion on MSDN that explains more of what is really a workaround suggested by #nunespascal:
Basically I can't set WindowState to Maximised in the Designer, but if I leave it set to Normal and then when loading the form in code I set it to Maximised it works.
This is also the answer provided in this StackOverflow post.

How to bring up a message popup in C#?

Most recently, while at my mom's house, a phone call came in and the caller ID popped up in a banner on her TV (Comcast). I've seen a similar functionality when the McAfee brings up a virus warning. It was a translucent popup window with the company logo, message and a button or two.
I'd like to mimic this behavior (via C#). This will event driven. My experience in C# is pretty limited, so I'm still feeling out the different libraries. Are there any ideas on where I should start?
I recommended to use WPF. Create new window, that will popup and set next properties:
WindowStyle="None"
AllowsTransparency="True"
Opacity="0.5" //50% transparent
Topmost="True"
Background property will set color of window.
Place on window any controls what you need.
Create this window and show when some event happens:
YourWindow popup = new YourWindow(/*possible args for message on popup, for example*/);
popup.Show();
To place your window in bottom-right corner, as all popups, use next code in windows Loaded event:
this.Left = SystemParameters.WorkArea.Width - this.Width;
this.Top = SystemParameters.WorkArea.Height - this.Height;
How to make animation of window movement you can read in other questions.
If your app is running in the background, you can simply pop up a window and set it to topmost.
Exactly what you do beyond that is going to depend on what type of UI are using (WPF/WinForms.) WPF makes it easier to build a transparent form, as described here:
http://blogs.interknowlogy.com/2007/06/20/transparent-windows-in-wpf-2/
Transparency in WinForms is a little bit harder, but there are some posts about it:
Partial transparency with C# .NET 3.5 WinForms?
A couple of things you will want to do with your pop-up window:
Disable the minimize/maximize/close buttons
Disable the borders
Just put those in your form so it looks better.
-- Dan

Get rid of XAML Window from Taskbar

If I have a XAML window that I show with ShowDialog, is there a way to make it (not) appear in the taskbar?
The problem is that I can set the window to be topmost but if that window opens another dialog and I set that also to be topmost, I can put the second behind the first by clicking in the taskbar. This tends to confuse users.
In your child window, set the ShowInTaskbar property to false.

Categories