Make my wpf application Full Screen (Cover taskbar and title bar of window)

后端 未结 9 1909
心在旅途
心在旅途 2020-12-05 14:34

I would like to make my application such that it can maximize to full screen means it hide the windows task bar and the title bar as well. And it should triggered by a butto

9条回答
  •  青春惊慌失措
    2020-12-05 15:15

    I had this issue with the taskbar staying on top of my window. The current solution i use is setting the window as Topmost for a short time, then setting it back to false (i want my window to work nice with Alt+Tab)

    private Timer t;
    public void OnLoad()
        {
            var window = Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive);
            StartTopmostTimer(window);
        }
    
        private void StartTopmostTimer(Window window)
        {
            t = new Timer(o => SetTopMostFalse(window), null, 1000, Timeout.Infinite);
        }
    
        private void SetTopMostFalse(Window window)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                window.Topmost = false;
            }));
            t.Dispose();
        }
    

    I also use this code to switch between full screen and window mode:

    public void SwitchFullScreen()
        {
            var window = Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive);
    
            if (window != null)
            {
                if (window.WindowStyle == WindowStyle.None)
                {
                    window.WindowStyle = WindowStyle.SingleBorderWindow;
                    window.WindowState = state;
                }
                else
                {
                    state = window.WindowState;
                    window.WindowStyle = WindowStyle.None;
                    window.WindowState = WindowState.Maximized;
                    window.Topmost = true;
                    StartTopmostTimer(window);
                }
            }
        }
    

提交回复
热议问题