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
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;
You can easily add the constraints on height in XAML by adding:
MaxHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}}"
into the Window's tag.
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
You may try this:
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;