Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:28:49+00:00 2026-06-15T11:28:49+00:00

I want the window to respect MinWidth / MinHeight and MaxWidth / MaxHeight specifications

  • 0

I want the window to respect MinWidth/MinHeight and MaxWidth/MaxHeight specifications of the content control inside.

Some suggested using SizeToContent, but this only helps to set the initial window size, not the constraints.

Others suggested overriding MeasureOverride and setting window’s Min/Max height and width there, but this seems to be somewhat unclean, considering that such a trivial problem should surely have a purely declarative solution.

Just to mention another solution which seems reasonable but does not work (and had been previously mentioned in an answer which got deleted): binding MinWidth of the window to MinWidth of the control does not take into account window decorations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:28:50+00:00Added an answer on June 15, 2026 at 11:28 am

    If the initial window size is set so that actual content size is not coerced by the content’s MinWidth/MinHeight and MaxWidth/MaxHeight in the initial layout pass (for example, by using Window.SizeToContent=”WidthAndHeight”), then following equations are true:

    Window.ActualSize - Content.ActualSize = 
          Window.MinSize - Content.MinSize = Window.MaxSize - Content.MaxSize.
    

    Based on these equations you can derive the following code:

    public MainWindow()
    {
        InitializeComponent();
    
        this.SizeChanged += OnWindowSizeChanged;
    }
    
    private static void OnWindowSizeChanged(object sender, SizeChangedEventArgs e)
    {
        var window = (Window)sender;
        var content = (FrameworkElement)window.Content;
    
        window.MinWidth = window.ActualWidth - content.ActualWidth + content.MinWidth;
        window.MaxWidth = window.ActualWidth - content.ActualWidth + content.MaxWidth;
    
        window.MinHeight = window.ActualHeight - content.ActualHeight + content.MinHeight;
        window.MaxHeight = window.ActualHeight - content.ActualHeight + content.MaxHeight;
    
        window.SizeChanged -= OnWindowSizeChanged;
    }
    

    I do not know how to achieve this efficiently using the pure declarative approach since the code should be ran just once after the initial layout pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want some window to never receive mouse wheel up/downs, i can control this
I am using Avalon in my WPF app. I want a window similar to
I want to have a window with the border radius of the content border
I want main window to gray, freeze, stop working, when some other window is
I want: if (window.XMLHttpRequest) { //do some } but after formatting I get: if
Using wxwidgets. I want a window without a border. I pass the follwoing flags
I want the window to be always in front of all of the app
I want my window to always maintain a certain ratio of let's say 1.33333333.
When I want a window to be transparent I have to set AllowsTransparency to
When i want to use window.external on internet explorer 9, it's always null. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.