简体   繁体   中英

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" . 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. 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:

/// <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. Otherwise, in some cases it works wrong. Also don't forget about ResizeMode.

And 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM