When creating a WPF window with AllowsTransparency="True" WindowStyle="None"
and maximizing it via
private void btnMaximize_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.MainWindow.WindowState != WindowState.Maximized)
Application.Current.MainWindow.WindowState = WindowState.Maximized;
else
Application.Current.MainWindow.WindowState = WindowState.Normal;
}
the Window gets bigger than my screen.
When I set ResizeMode
to ResizeMode="NoResize"
it works like a charm.
But I want to resize my window. Any suggestions how to fix my problem?
CodePudding user response:
You can set the MaxHeight property of that window to SystemParameters.MaximizedPrimaryScreenHeight in the constructor. This might not work on extended desktop.
public MainWindow()
{
InitializeComponent();
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
}
CodePudding user response:
Try using SystemParameters like this.
private void btnMaximize_Click(object sender, RoutedEventArgs e)
{
this.Height = SystemParameters.MaximizedPrimaryScreenHeight;
}