AUTOMATICALLY SIZED WINDOWS
In this example, there??™s still one element that has hard-coded sizes: the top-level window that contains the
StackPanel (and everything else inside). For a number of reasons, it still makes sense to hard-code window
sizes:
??? In many cases, you want to make a window smaller than the desired size of its child elements. For
example, if your window includes a container of scrollable text, you??™ll want to constrain the size of that
container so that scrolling is possible. You don??™t want to make the window ridiculously large so that no
scrolling is necessary, which is what the container will request. (You??™ll learn more about scrolling in
Chapter 5.)
??? The minimum window size may be usable, but it might not give you the most attractive proportions.
Some window dimensions just look better.
??? Automatic window sizing isn??™t constrained by the display size of your monitor. So an automatically
sized window might be too large to view.
However, automatically sized windows are possible, and they do make sense if you are constructing a
simple window with dynamic content. To enable automatic window sizing, remove the Height and Width
properties and set the Window.SizeToContent property to WidthAndHeight. The window will make itself just
large enough to accommodate all its content.
Pages:
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214