How to make full screen mode, without covering the taskbar using :wpf c#

前端 未结 6 1363
谎友^
谎友^ 2020-12-17 17:44

I need to change windows taskbar in my WPF application. For that I set WindowStyle=\"None\", which means to disable the windows taskbar, and make custom taskbar

6条回答
  •  醉话见心
    2020-12-17 18:11

    Proposed solution worked for me but still need to correct pixel to dpi setter values for window to have correct size regardless user settings:

    in xaml :

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

    in code :

    public MainWindow()
    {
        InitializeComponent();
        var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
        var pixelWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width ;
        var pixelHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
        var pixelToDPI = 96.0 / graphics.DpiX ;
        this.Width = pixelWidth * pixelToDPI;
        this.Height = pixelHeight * pixelToDPI;
        this.Left = 0;
        this.Top = 0;
        this.WindowState = WindowState.Normal;
    }
    

提交回复
热议问题