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.
我正在尝试创建一个WPF窗口,该窗口已经最大化打开,没有调整/移动(在systemmenu中,也没有边框中)。它应该一直最大化,除非用户最小化它。
I tried to put WindowState="Maximized" and ResizeMode="CanMinimize", but when window opens, it covers the task bar (i don't want it).
我试图将WindowState="Maximized"和ResizeMode=" can最小化"放在窗口打开时,它会覆盖任务栏(我不想要它)。
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.
我有一个与WndProc的挂钩,它取消了SC_MOVE和SC_SIZE。我还可以使用WndProc中的条件来做这个控件,比如“if命令是恢复的,并且最小化了,恢复了,否则,块”等等。
But my point is if we have another way to make it. Thankz for read guys =)
但我的观点是如果我们有另一种方法。谢谢大家阅读=)
4 个解决方案
#1
13
It is necessary to write WindowState="Maximized" ResizeMode="NoResize"
in xaml of your window:
需要在窗口的xaml中写入WindowState="Maximized" ResizeMode="NoResize":
<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>
#2
2
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;
}
#3
1
As Tergiver pointed out, this is not possible in a purely WPF manner. You have to use P/Invoke. As for why the window covers the taskbar when it opens, I think you are messing up some required calls by canceling SC_MOVE and SC_SIZE. Maybe you should cancel those calls after the window has been loaded.
正如tergiving指出的,这是不可能的,仅仅以WPF的方式。您必须使用P/Invoke。至于为什么窗口在打开时覆盖任务栏,我认为取消SC_MOVE和SC_SIZE会使一些必需的调用变得混乱。也许您应该在窗口加载后取消那些调用。
#4
0
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
WindowStyle="None" do what you want, but... you lose the window title, close button and have other problems.
WindowStyle="None"做你想做的事,但是…你失去窗口标题,关闭按钮和其他问题。
Visit WindowStyle="None" some problems
访问WindowStyle = "没有"一些问题
#1
13
It is necessary to write WindowState="Maximized" ResizeMode="NoResize"
in xaml of your window:
需要在窗口的xaml中写入WindowState="Maximized" ResizeMode="NoResize":
<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>
#2
2
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;
}
#3
1
As Tergiver pointed out, this is not possible in a purely WPF manner. You have to use P/Invoke. As for why the window covers the taskbar when it opens, I think you are messing up some required calls by canceling SC_MOVE and SC_SIZE. Maybe you should cancel those calls after the window has been loaded.
正如tergiving指出的,这是不可能的,仅仅以WPF的方式。您必须使用P/Invoke。至于为什么窗口在打开时覆盖任务栏,我认为取消SC_MOVE和SC_SIZE会使一些必需的调用变得混乱。也许您应该在窗口加载后取消那些调用。
#4
0
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
WindowStyle="None" do what you want, but... you lose the window title, close button and have other problems.
WindowStyle="None"做你想做的事,但是…你失去窗口标题,关闭按钮和其他问题。
Visit WindowStyle="None" some problems
访问WindowStyle = "没有"一些问题