Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set the PREFERRED size of a WPF control
    text
    copied!<p>Is there a way to set the <strong>preferred</strong> size of a WPF control without setting its maximum size?</p> <p>I normally set all of my WPF controls to have have automatic height and width, and I set the alignment to stretch. That works great in a lot of cases. My windows come up in a reasonable size by default. If the user stretches the window, the extra space will go where I think it should.</p> <p>This broke when I set the width of a DataGridTextColumn to "*". Now suddenly the preferred size for my table is several times bigger than my screen! The initial size for my window is exactly the size of my screen.</p> <p>Of course, I could set the MaxWidth of my table (or my column), but I don't want to do that. The <strong>max</strong> width was fine at infinity. </p> <p>I tried changing the Width property to a fixed number of pixels. That seems to change the <strong>maximum</strong> width. Even though I set HorizontalContentAlignment="Stretch" in the table, the table is centered and the width does not change.</p> <p>Is there a way around this? I like auto-sizes most of the time. And I like setting the width of a column to "*". Is there a way to make them work together?</p> <p>It seems like there's a property somewhere that I can't find. At some point the container has to ask my table what size it wants to be. That answer might be ignored or adjusted, but the table had to answer that question. It seems like I should be able to change that value, without changing the max size. (And it seems like if I say "stretch" and there is extra space, my table should be stretched.)</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload