WPF如何在最大化窗口时免除任务栏

时间:2012-05-21 06:22:32

标签: wpf windows

我有一个wpf窗口,我应用了窗口标题的样式,并添加了一些代码来最大化窗口,当我点击最大化按钮并且工作正常时覆盖任务栏。但问题是当我通过隐藏任务栏将窗口拖向顶部窗口最大化时,任何人都可以帮助我摆脱这个。

谢谢, @nagaraju。

dragmove的代码:

void OnTitleBarLeftButtonDown(object sender, MouseEventArgs e)
        {                          
                Window window = this.TemplatedParent as Window;
                if (window != null)
                {
                    window.DragMove();
                }            
        }

最大化代码:

void MaxButton_Click(object sender, RoutedEventArgs e)
        {
            Window window = this.TemplatedParent as Window;
            if (window != null)
            {
                if (state=="MAX")
                {
                    window.Width = 1181;
                    window.Height = 670;
                    window.WindowState = WindowState.Normal;
                    CenterWindowOnScreen();
                    state = "MIN";                    
                }
                else
                {
                    //maxButton.ImageDown = "/images/normalpress.png";
                    //maxButton.ImageNormal = "/images/normal.png";
                    //maxButton.ImageOver = "/images/normalhot.png";
                    state = "MAX";
                    window.Width = SystemParameters.WorkArea.Width;
                    window.Height = SystemParameters.WorkArea.Height;
                    window.Top = SystemParameters.WorkArea.Top;
                    window.Left = SystemParameters.WorkArea.Left;
                }
            }
        }

1 个答案:

答案 0 :(得分:1)

避免很多麻烦,不要自己这样做 - 使用shell integration library

相关问题