Figure 4-7 sheds some light on how this works with the StackPanel. On the left is the
window at its minimum size. The buttons are 100 units each, and the window cannot be
resized to be narrower. If you shrink the window from this point, the right side of each button
will be clipped off. (You can prevent this possibility by applying the MinWidth property to the
window itself, so the window can??™t go below a minimum width.)
As you enlarge the window, the buttons grow with it until they reach their maximum of
200 units. From this point on, if you make the window any larger the extra space is added to
either side of the button (as shown on the right).
CHAPTER 4 n LAYOUT 87
Figure 4-7. Constrained button sizing
nNote In some situations, you might want to use code that checks how large an element is in a window.
The Height and Width properties are no help because they indicate your desired size settings, which might
not correspond to the actual rendered size. In an ideal scenario, you??™ll let your elements size to fit their content,
and the Height and Width properties won??™t be set at all. However, you can find out the actual size used
to render an element by reading the ActualHeight and ActualWidth properties. But remember, these values
may change when the window is resized or the content inside it changes.
Pages:
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213