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

时间:2014-06-12 16:19:02

标签: c# wpf user-interface taskbar

如何在WindowStyle="None"时看到任务栏。我试图通过删除实际的窗口标题栏并使用dll删除边框来拥有自己的按钮(关闭,最大化,最小化)。非常感谢易于维护和易于放入我的代码。

先谢谢!

1 个答案:

答案 0 :(得分:0)

执行此操作的可能方法之一是:限制窗口的最大大小。例如:

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;
        }
    }
}

您需要在更改窗口状态之前设置maxsize。否则,在某些情况下它工作错误。也不要忘记ResizeMode。

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