简体   繁体   English

WPF | C#-当WindowStyle =“ None”并且窗口最大化时,任务栏不显示

[英]WPF | C# - When WindowStyle = “None” and the window is maximized the Task Bar doesn't show up

How can I be able to see the taskbar when WindowStyle="None" . WindowStyle="None"时,如何查看任务栏。 I'm trying to have my own buttons (Close, Maximize, Minimize) by removing the actual window title bar and using a dll too remove the border. 我试图通过删除实际的窗口标题栏并使用dll来删除边框,以拥有自己的按钮(关闭,最大化,最小化)。 Easy to maintain and easy to put in my code would be greatly appreciated. 易于维护和易于放入我的代码将不胜感激。

Thanks in advanced! 提前致谢!

One of the possible fix to do this is: to limit the max size of window. 可能的解决方法之一是:限制窗口的最大大小。 For example: 例如:

C# code: C#代码:

/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
       if (WindowState == WindowState.Normal)
        {
            System.Drawing.Rectangle rec = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle).WorkingArea;
            MaxHeight = rec.Height;
            MaxWidth = rec.Width;
            ResizeMode = ResizeMode.NoResize;
            WindowState = WindowState.Maximized;
        }
        else
        {
            MaxHeight = double.PositiveInfinity;
            MaxWidth = double.PositiveInfinity;
            ResizeMode = ResizeMode.CanResize;
            WindowState = WindowState.Normal;
        }
    }
}

You need to set maxsize just before changing of window state. 您需要在更改窗口状态之前设置maxsize。 Otherwise, in some cases it works wrong. 否则,在某些情况下它会出错。 Also don't forget about ResizeMode. 同样不要忘记ResizeMode。

And xaml: 和xaml:

<Window x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" WindowStyle="None" Height="300" Width="300">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75" Click="ButtonBase_OnClick"/>
    </Grid>
</Window>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用键盘SHIFT + WIN + LEFT / RIGHT,最大化了WindowStyle =“ None”的窗口不会再次移动 - Maximized window with WindowStyle=“None” doesn't move again using keyboard SHIFT+WIN+LEFT/RIGHT WindowStyle为SingleBorderWindow时以最大化状态隐藏任务栏 - Hide task bar in maximized state when WindowStyle is SingleBorderWindow WindowStyle =没有窗口最大化黑客无法与多个监视器一起使用 - WindowStyle=None and window maximized hack not working with multiple monitors C#WPF SizeChanged事件在最大化时不更新宽度和高度 - C# WPF SizeChanged event doesn't update width and height when maximized C#WPF最大化Window的位置 - C# WPF Maximized Window's position 启动画面后没有显示最大化的窗口 - Maximized window doesn't show after splashscreen C# Winforms 锚定在启动最大化时不起作用 - C# Winforms anchoring doesn't work when started maximized 在WPF窗口中修改调整大小夹点的光标(“CanResizeWithGrip”+“WindowStyle:none”) - Modifying the cursor of a resize grip in a WPF window (“CanResizeWithGrip” + “WindowStyle:none”) 如何在功能区窗口中显示状态栏wpf c# - how to show status bar in ribbon window wpf c# WPF:输出正确,但窗口未显示 - WPF: The Output is Correct But the Window doesn't show up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM