我有一个Windows 8.1 wpf应用程序,可以更改其模式:自助服务终端或维护 . 对于自助服务终端模式,我有一个代码:

window.WindowStyle = WindowStyle.None; window.WindowState = WindowState.Maximized; window.Topmost = true;

它工作得非常好,但是当我将模式从维护模式更改为kiosk模式时,我遇到了一个问题:如果窗口最大化之前(window.WindowState == WindowState.Maximized),任务栏保持可见 . 我试过解决这个问题:我使用User32.dll计算了监视器的宽度和高度:

public MainWindow()
    {
        InitializeComponent();
        this.SourceInitialized += new EventHandler(win_SourceInitialized);
    }

    void win_SourceInitialized(object sender, EventArgs e)
    {
        System.IntPtr handle = (new WindowInteropHelper(this)).Handle;
        HwndSource.FromHwnd(handle).AddHook(new HwndSourceHook(WindowProc));
    }
    private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        switch (msg)
        {
            case 0x0024:
                WmGetMinMaxInfo(hwnd, lParam);
                handled = true;
                break;
        }
        return (IntPtr)0;
    }

    private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
    {
        MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

        // Adjust the maximized size and position to fit the work area of the correct monitor
        int MONITOR_DEFAULTTONEAREST = 0x00000002;
        System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

        if (monitor != System.IntPtr.Zero)
        {
            MONITORINFO monitorInfo = new MONITORINFO();
            GetMonitorInfo(monitor, monitorInfo);
            RECT rcMonitorArea = monitorInfo.rcMonitor;
            mmi.ptMaxPosition.x = rcMonitorArea.left;
            mmi.ptMaxPosition.y = rcMonitorArea.top;
            mmi.ptMaxSize.x = Math.Abs(rcMonitorArea.right - rcMonitorArea.left);
            mmi.ptMaxSize.y = Math.Abs(rcMonitorArea.bottom - rcMonitorArea.top);
        }
        Marshal.StructureToPtr(mmi, lParam, true);
    }

    [DllImport("user32.dll")]
    internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);

    [DllImport("user32.dll")]
    static extern bool GetCursorPos(ref Point lpPoint);

    [DllImport("User32.dll")]
    internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);

但是,无论是在维护模式窗口最大化之后,它都无法正常工作 . 我知道WindowState已经是WindowState.Maximized,并且不会发生更改窗口大小的事件 . 但我不知道如何解决它 . 当然,我可以在最大化之前更改窗口的大小:

window.WindowStyle = WindowStyle.None;
window.WindowState = WindowState.Normal;
window.WindowState = WindowState.Maximized;
window.Topmost = true;

它工作,但我看到窗口的闪烁 . 这对我来说非常糟糕 . 我希望有人有这个错误,他很高兴地解决了这个问题 .