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 with buttons for restoring, minimizing and closing the application. Now my problem is if the application is in maximize mode then I can't see the start menu on windows.
I found a similar question here, but when I tried this code it didn't compile. full screen mode, but don't cover the taskbar
How can I create my own taskbar and able to see the windows start menu when I maximized it? Is there a property window in xaml which can set it?
You may try this:
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
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;
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;
}
WindowStyle="None"
AllowsTransparency="True"
and
this.Top = 0;
this.Left = 0;
this.Width = SystemParameters.WorkArea.Width;
this.Height = SystemParameters.WorkArea.Height;
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
来源:https://stackoverflow.com/questions/35009880/how-to-make-full-screen-mode-without-covering-the-taskbar-using-wpf-c-sharp