WPF- ( , ). - . , Windows.
, System.Windows.SystemParameters , . 1920x1080.
PrimaryScreenHeight - 1080. , Windows.WorkArea.Height - 1040.FullPrimaryScreenHeight - 1018. .
, WorkArea.Height:
protected T SetWindowLocation<T>(T window) where T : Window
{
const int absoluteMinWidth = 1024;
const int absoluteMinHeight = 768;
const int absoluteMaxWidth = 1400;
const int absoluteMaxHeight = 900;
var maxHeightForMonitor = System.Windows.SystemParameters.WorkArea.Height - 100;
var maxWidthForMonitor = System.Windows.SystemParameters.WorkArea.Width - 100;
var height = Math.Min(Math.Max(maxHeightForMonitor, absoluteMinHeight), absoluteMaxHeight);
var width = Math.Min(Math.Max(maxWidthForMonitor, absoluteMinWidth), absoluteMaxWidth);
window.Height = height;
window.Width = width;
window.Left = (System.Windows.SystemParameters.FullPrimaryScreenWidth - width) / 2;
window.Top = (System.Windows.SystemParameters.FullPrimaryScreenHeight - height) / 2;
window.WindowStartupLocation = WindowStartupLocation.Manual;
return window;
}
source
share