Search code examples
wpf

WPF reset maxWidth and maxHeight to default


I have a window app and it updates dynamically, an issue I have is removing the maxWidth and maxHeight set to the window, I must have a maxWidth and maxHeight in some scenarios as per the company requirements but at points I need to remove the max limits for other scenarios.

All I want to know is how to remove the maxWidth and maxHeight, I assume it is possible.


Solution

  • You can set the MaxWidth and MaxHeight property of a WPF window to double.PositiveInfinity which is the default value for both. This will remove any max constraint:

    //store the current/previous value
    double oldMaxWidth = this.MaxWidth;
    //remove the constraint
    this.MaxWidth = double.PositiveInfinity;