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

前端 未结 6 1335
谎友^
谎友^ 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

    Found a solution on CodeProject which may help: http://www.codeproject.com/Articles/107994/Taskbar-with-Window-Maximized-and-WindowState-to-N

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

    and

    this.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
    this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
    this.Left = 0;
    this.Top = 0;
    this.WindowState = WindowState.Normal;
    
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
  • 2020-12-17 18:26
    WindowStyle="None" 
    AllowsTransparency="True"  
    

    and

    this.Top = 0;
    this.Left = 0;
    this.Width = SystemParameters.WorkArea.Width;
    this.Height = SystemParameters.WorkArea.Height;
    
    0 讨论(0)
  • 2020-12-17 18:26

    You can easily add the constraints on height in XAML by adding:

    MaxHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}}"
    

    into the Window's tag.

    0 讨论(0)
  • 2020-12-17 18:30

    Solution for WPF

    Let's say we want to place the mainWindow of a WPF project at the bottom-right of the screen without it covering the taskBar. We'll write this:

    public MainWindow()
        {
            InitializeComponent();
            // set position of window on screen
            this.Left = SystemParameters.PrimaryScreenWidth - this.Width;
            this.Top = SystemParameters.WorkArea.Bottom - this.Height;
        }
    

    this = our object (the MainWindow) We first get to place the left parameter when we subtract our window position (left) from the PrimarySrceenWidth. Than, we do the same to get the most lower point, by subtracting the windows height from the working area of the screen bottom. The working area of the screen does not include the task bar!

    enjoy!

    Avri

    0 讨论(0)
  • 2020-12-17 18:34

    You may try this:

    MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
    MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
    
    0 讨论(0)
提交回复
热议问题