0

I am using this in XAML to center the screen,

WindowStartupLocation="CenterScreen"

To center the window on the users screen, but when the screen resolution is quite small the Title Bar is out of the screen range. Obviously when this happens, the users can't close down the program and on particularly small screens some of the Tab Controls are not visible.

How do I make the screen center along with always showing the Title Bar?

KyloRen
  • 2,691
  • 5
  • 29
  • 59
  • You mean you need to resize your window to fit the screen resolution before moving the window to the center of screen? – grek40 Jan 26 '17 at 14:43
  • @grek40, I want to keep the window size, but make sure that the title is always visible. Unless I should be adjusting the window size to suit the screen??? – KyloRen Jan 26 '17 at 14:43
  • I know this doesn't solve your problem, but Alt-F4 will close the window that has focus even if the title bar is off screen. – Kevin Jan 26 '17 at 14:50
  • @Kevin, unfortunately you can't tell every user what to do. – KyloRen Jan 26 '17 at 14:51
  • For what you are asking, you aren't going to be able to use CenterScreen. You'll have to determine the screen dimentions and calculate a top/left point on the screen that gives you the visibility you want, then move the screen location to that point. – Kevin Jan 26 '17 at 14:54
  • @Kevin, I feared as much. – KyloRen Jan 26 '17 at 14:54

1 Answers1

2

How do I make the screen center along with always showing the Title Bar?

You will have to programmatically adjust the size of the window. You could for example set the MaxWidth and MaxHeight properties based on the SystemParameters.PrimaryScreenWidth and SystemParameters.PrimaryScreenWidth values respectively:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        MaxHeight = SystemParameters.PrimaryScreenHeight - SystemParameters.CaptionHeight;
        MaxWidth = SystemParameters.PrimaryScreenWidth;
    }
}

You could also refer to the following question:

How do you center your main window in WPF?

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88