时间:2010-07-23 13:08:38

标签: wpf window window-resize maximize-window

4 个答案:

答案 0 :(得分:16)

有必要在窗口的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>

答案 1 :(得分:3)

    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;
    }

答案 2 :(得分:1)

正如Tergiver指出的那样,纯粹的WPF方式是不可能的。你必须使用P / Invoke。至于窗口打开时窗口覆盖任务栏的原因,我认为你通过取消SC_MOVE和SC_SIZE搞乱了一些必要的调用。也许你应该在窗口加载后取消这些调用。

答案 3 :(得分:1)

WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"

WindowStyle =&#34;无&#34;做你想做的,但是...你失去了窗口标题,关闭按钮并有其他问题。

访问WindowStyle="None" some problems