首页 文章

如何制作全屏模式,而不使用以下任务栏覆盖任务栏:wpf c#

提问于
浏览
8

我需要在WPF应用程序中更改Windows任务栏 . 为此我设置 WindowStyle="None" ,这意味着禁用Windows任务栏,并使用按钮进行自定义任务栏以恢复,最小化和关闭应用程序 . 现在我的问题是如果应用程序处于最大化模式,那么我无法在Windows上看到开始菜单 .

我在这里找到了一个类似的问题,但是当我尝试这个代码时它没有编译 . full screen mode, but don't cover the taskbar

如何创建自己的任务栏并在最大化时能够看到Windows开始菜单? xaml中是否有可以设置的属性窗口?

5 回答

  • 0

    你可以试试这个:

    MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
    MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
    
  • 14

    在CodeProject上找到了一个可能有帮助的解决方案:http://www.codeproject.com/Articles/107994/Taskbar-with-Window-Maximized-and-WindowState-to-N

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

    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;
    
  • 2

    建议的解决方案适用于我 but 仍然需要更正窗口的像素到dpi setter值,无论用户设置如何都具有正确的大小:

    在xaml中:

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

    在代码中:

    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
    WindowStyle="None" 
    AllowsTransparency="True"
    

    this.Top = 0;
    this.Left = 0;
    this.Width = SystemParameters.WorkArea.Width;
    this.Height = SystemParameters.WorkArea.Height;
    
  • 1

    Solution for WPF

    假设我们想要将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 =我们的对象(MainWindow)当我们从PrimarySrceenWidth中减去窗口位置(左)时,我们首先得到左参数 . 然而,我们通过从屏幕底部的工作区域减去窗口高度来获得最低点 . 屏幕的工作区域不包括任务栏!

    请享用!

    Avri

相关问题