如何使用:wpf c#制作全屏模式,而不覆盖任务栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35009880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make full screen mode, without covering the taskbar using :wpf c#
提问by Evgeni Velikov
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.
我需要在我的 WPF 应用程序中更改 Windows 任务栏。为此,我设置了WindowStyle="None",这意味着禁用 Windows 任务栏,并使用用于恢复、最小化和关闭应用程序的按钮制作自定义任务栏。现在我的问题是如果应用程序处于最大化模式,那么我在 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?
如何创建自己的任务栏并在最大化时能够看到 Windows 开始菜单?xaml 中是否有可以设置它的属性窗口?
回答by Pikoh
You may try this:
你可以试试这个:
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
回答by M. Schena
Found a solution on CodeProject which may help: http://www.codeproject.com/Articles/107994/Taskbar-with-Window-Maximized-and-WindowState-to-N
在 CodeProject 上找到了一个可能有帮助的解决方案: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;
回答by Hafizul Amri
WindowStyle="None"
AllowsTransparency="True"
and
和
this.Top = 0;
this.Left = 0;
this.Width = SystemParameters.WorkArea.Width;
this.Height = SystemParameters.WorkArea.Height;
回答by Nicolas
Proposed solution worked for me butstill need to correct pixel to dpi setter values for window to have correct size regardless user settings:
建议的解决方案对我有用,但仍然需要将像素更正为窗口的 dpi 设置器值以具有正确的大小,无论用户设置如何:
in xaml :
在 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;
}
回答by Dr. Avri
Solution for WPF
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:
假设我们想将 WPF 项目的 mainWindow 放置在屏幕的右下角而不覆盖 taskBar。我们会这样写:
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!
this = 我们的对象(MainWindow) 当我们从 PrimarySrceenWidth 中减去我们的窗口位置(左)时,我们首先要放置左参数。然后,我们通过从屏幕底部的工作区域中减去窗口高度来获得最低点。屏幕的工作区不包括任务栏!
enjoy!
请享用!
Avri
艾薇

