3

I have created a borderless window in WPF. I have written a event to maximize the window but on maximizing, part of the window sometimes hides behind the task bar and after a moment appears on top of the task bar.

How can I ensure that the window remains on top of task bar every time ? Following is the way I have implemented:

private void OnMaximizedClicked(object sender, RoutedEventArgs e)
{
    this.WindowState = this.WindowState != WindowState.Normal ? WindowState.Normal : WindowState.Maximized;
}

I have tried setting the TopMost property to true, but didn't help me either.

2 Answers2

1

This will fix it, but I feel there should be a more elegant way:

this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
this.WindowState = this.WindowState != WindowState.Normal 
                 ? WindowState.Normal : WindowState.Maximized;
this.WindowStyle = System.Windows.WindowStyle.None;

Btw, I adapted it from this WinForms answer. So it's not WPF related and you can throw a wider search net.

Community
  • 1
  • 1
H H
  • 263,252
  • 30
  • 330
  • 514
  • 1
    When I set the WindowStyle after maximizing, the window overflows the screen by about 8 pixels (appears to be on all sides), rather than maximizing properly. – Kendall Frey Dec 27 '14 at 01:11
0

Setting ResizeMode to NoResize helped on my case:

ResizeMode="NoResize"
Panu Oksala
  • 3,245
  • 1
  • 18
  • 28