I'm trying to make a WPF window that opens already maximized, with no resize/move (in systemmenu, nor in border). It should be maximized all the time, except when the user minimize it.
I tried to put WindowState="Maximized" and ResizeMode="CanMinimize", but when window opens, it covers the task bar (i don't want it).
I have an hook to WndProc that cancels the SC_MOVE and SC_SIZE. I also can make this control with conditions in WndProc like "if command is restore and is minimized, restore, else, block" and so on.
But my point is if we have another way to make it. Thankz for read guys =)
It is necessary to write WindowState="Maximized" ResizeMode="NoResize"
in xaml of your window:
<Window x:Class="Miscellaneous.EditForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Edit Form" WindowState="Maximized" ResizeMode="NoResize"></Window>
public Window1()
{
InitializeComponent();
this.SourceInitialized += Window1_SourceInitialized;
}
private void Window1_SourceInitialized(object sender, EventArgs e)
{
WindowInteropHelper helper = new WindowInteropHelper(this);
HwndSource source = HwndSource.FromHwnd(helper.Handle);
source.AddHook(WndProc);
}
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_SYSCOMMAND:
int command = wParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
{
handled = true;
}
break;
default:
break;
}
return IntPtr.Zero;
}
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
WindowStyle="None" do what you want, but... you lose the window title, close button and have other problems.
Visit WindowStyle="None" some problems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With