如何在鳕鱼中全屏制作WPF应用程序?

时间:2015-07-30 17:37:22

标签: c# wpf

当我在XAML中设置'WindowState.Maximized'和'WindowStyle.None'时效果很好,但在代码中这不起作用。 TaskBar不会消失。谁知道问题出在哪里?

private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (MWindow.WindowStyle != WindowStyle.None)
        { 
            MWindow.WindowState = WindowState.Maximized;
            MWindow.WindowStyle = WindowStyle.None;
        }
        else
        {
            MWindow.WindowStyle = WindowStyle.SingleBorderWindow;
            MWindow.WindowState = WindowState.Normal;
        }          
    }

3 个答案:

答案 0 :(得分:0)

if (this.WindowStyle != WindowStyle.None)
{
     this.WindowStyle = WindowStyle.None;
     this.WindowState = WindowState.Maximized;
}
else
{
     this.WindowStyle = WindowStyle.SingleBorderWindow;
     this.WindowState = WindowState.Normal;
}    

答案 1 :(得分:0)

您可以通过处理Activated事件或从App类重写OnActivated方法,并从主窗口huckup到ContentRendered事件来实现。您也可以在窗口本身处理ContentRendered,但请注意,使用此方法无需知道主窗口的实际位置:

protected override void OnActivated(EventArgs e)
{
    base.OnActivated(e);


    Application.Current.MainWindow.ContentRendered += (s, a) =>
    {
        if (Application.Current.MainWindow.WindowStyle != WindowStyle.None)
        {
            Application.Current.MainWindow.WindowState = WindowState.Maximized;
            Application.Current.MainWindow.WindowStyle = WindowStyle.None;
        }
        else
        {
            Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
            Application.Current.MainWindow.WindowState = WindowState.Normal;
        }
    };

}

答案 2 :(得分:0)

在您设置分辨率之前,任务栏不会消失:

MyWindow.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
MyWindow.Width = System.Windows.SystemParameters.PrimaryScreenWidth;